Chilkat Online Tools

unicodeC / New FreshBooks / Edit Vendor Details

Back to Collection Items

#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkHttpResponseW.h>

void ChilkatSample(void)
    {
    HCkHttpW http;
    BOOL success;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkHttpResponseW resp;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *Amount;
    const wchar_t *Code;
    const wchar_t *Account_number;
    const wchar_t *City;
    const wchar_t *Country;
    const wchar_t *Created_at;
    const wchar_t *Currency_code;
    BOOL Is_1099;
    const wchar_t *Language;
    const wchar_t *Phone;
    const wchar_t *Postal_code;
    const wchar_t *Primary_contact_email;
    const wchar_t *Primary_contact_first_name;
    const wchar_t *Primary_contact_last_name;
    const wchar_t *Province;
    const wchar_t *Street;
    const wchar_t *Street2;
    const wchar_t *Updated_at;
    const wchar_t *Vendor_name;
    int Vendorid;
    int Vis_state;
    const wchar_t *Website;
    int i;
    int count_i;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http = CkHttpW_Create();

    // Use this online tool to generate code from sample JSON: Generate Code to Create JSON

    // The following JSON is sent in the request body.

    // {
    //   "bill_vendor": {
    //     "vendor_name": "IKEA",
    //     "primary_contact_first_name": "Jimmy",
    //     "primary_contact_last_name": "McNamara",
    //     "primary_contact_email": "jimmym@ikea.com",
    //     "primary_contact": null,
    //     "street": "332 Carlton Ave.",
    //     "street2": null,
    //     "city": "San Francisco",
    //     "province": "California",
    //     "postal_code": null,
    //     "country": "United States",
    //     "account_number": "45454545",
    //     "phone": "4158859378",
    //     "website": "ikea.com",
    //     "currency_code": "USD",
    //     "language": "en",
    //     "is_1099": false,
    //     "tax_defaults": [
    //     ]
    //   }
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"bill_vendor.vendor_name",L"IKEA");
    CkJsonObjectW_UpdateString(json,L"bill_vendor.primary_contact_first_name",L"Jimmy");
    CkJsonObjectW_UpdateString(json,L"bill_vendor.primary_contact_last_name",L"McNamara");
    CkJsonObjectW_UpdateString(json,L"bill_vendor.primary_contact_email",L"jimmym@ikea.com");
    CkJsonObjectW_UpdateNull(json,L"bill_vendor.primary_contact");
    CkJsonObjectW_UpdateString(json,L"bill_vendor.street",L"332 Carlton Ave.");
    CkJsonObjectW_UpdateNull(json,L"bill_vendor.street2");
    CkJsonObjectW_UpdateString(json,L"bill_vendor.city",L"San Francisco");
    CkJsonObjectW_UpdateString(json,L"bill_vendor.province",L"California");
    CkJsonObjectW_UpdateNull(json,L"bill_vendor.postal_code");
    CkJsonObjectW_UpdateString(json,L"bill_vendor.country",L"United States");
    CkJsonObjectW_UpdateString(json,L"bill_vendor.account_number",L"45454545");
    CkJsonObjectW_UpdateString(json,L"bill_vendor.phone",L"4158859378");
    CkJsonObjectW_UpdateString(json,L"bill_vendor.website",L"ikea.com");
    CkJsonObjectW_UpdateString(json,L"bill_vendor.currency_code",L"USD");
    CkJsonObjectW_UpdateString(json,L"bill_vendor.language",L"en");
    CkJsonObjectW_UpdateBool(json,L"bill_vendor.is_1099",FALSE);
    CkJsonObjectW_UpdateNewArray(json,L"bill_vendor.tax_defaults");

    // Adds the "Authorization: Bearer <access_token>" header.
    CkHttpW_putAuthToken(http,L"<access_token>");

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);

    resp = CkHttpW_PTextSb(http,L"PUT",L"https://api.freshbooks.com/accounting/account/{{accountId}}/bill_vendors/bill_vendors/{{vendorId}}",sbRequestBody,L"utf-8",L"application/json",FALSE,FALSE);
    if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        return;
    }

    sbResponseBody = CkStringBuilderW_Create();
    CkHttpResponseW_GetBodySb(resp,sbResponseBody);

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",CkJsonObjectW_emit(jResp));

    respStatusCode = CkHttpResponseW_getStatusCode(resp);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpResponseW_header(resp));
        wprintf(L"Failed.\n");
        CkHttpResponseW_Dispose(resp);
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        return;
    }

    CkHttpResponseW_Dispose(resp);

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "response": {
    //     "result": {
    //       "bill_vendor": {
    //         "account_number": "45454545",
    //         "city": "San Francisco",
    //         "country": "United States",
    //         "created_at": "2020-10-09 15:25:05",
    //         "currency_code": "USD",
    //         "is_1099": false,
    //         "language": "en",
    //         "outstanding_balance": [
    //           {
    //             "amount": {
    //               "amount": "450.00",
    //               "code": "USD"
    //             }
    //           }
    //         ],
    //         "overdue_balance": [
    //         ],
    //         "phone": "4158859378",
    //         "postal_code": null,
    //         "primary_contact_email": "jimmym@ikea.com",
    //         "primary_contact_first_name": "Jimmy",
    //         "primary_contact_last_name": "McNamara",
    //         "province": "California",
    //         "street": "332 Carlton Ave.",
    //         "street2": null,
    //         "tax_defaults": [
    //         ],
    //         "updated_at": "2020-10-09 15:39:10",
    //         "vendor_name": "IKEA",
    //         "vendorid": 5,
    //         "vis_state": 0,
    //         "website": "ikea.com"
    //       }
    //     }
    //   }
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    Account_number = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.account_number");
    City = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.city");
    Country = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.country");
    Created_at = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.created_at");
    Currency_code = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.currency_code");
    Is_1099 = CkJsonObjectW_BoolOf(jResp,L"response.result.bill_vendor.is_1099");
    Language = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.language");
    Phone = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.phone");
    Postal_code = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.postal_code");
    Primary_contact_email = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.primary_contact_email");
    Primary_contact_first_name = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.primary_contact_first_name");
    Primary_contact_last_name = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.primary_contact_last_name");
    Province = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.province");
    Street = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.street");
    Street2 = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.street2");
    Updated_at = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.updated_at");
    Vendor_name = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.vendor_name");
    Vendorid = CkJsonObjectW_IntOf(jResp,L"response.result.bill_vendor.vendorid");
    Vis_state = CkJsonObjectW_IntOf(jResp,L"response.result.bill_vendor.vis_state");
    Website = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.website");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"response.result.bill_vendor.outstanding_balance");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        Amount = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.outstanding_balance[i].amount.amount");
        Code = CkJsonObjectW_stringOf(jResp,L"response.result.bill_vendor.outstanding_balance[i].amount.code");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"response.result.bill_vendor.overdue_balance");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"response.result.bill_vendor.tax_defaults");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(json);
    CkStringBuilderW_Dispose(sbRequestBody);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-d '{
    "bill_vendor": {
        "vendor_name": "IKEA",
        "primary_contact_first_name": "Jimmy",
        "primary_contact_last_name": "McNamara",
        "primary_contact_email": "jimmym@ikea.com",
        "primary_contact": null,
        "street": "332 Carlton Ave.",
        "street2": null,
        "city": "San Francisco",
        "province": "California",
        "postal_code": null,
        "country": "United States",
        "account_number": "45454545",
        "phone": "4158859378",
        "website": "ikea.com",
        "currency_code": "USD",
        "language": "en",
        "is_1099": false,
        "tax_defaults": []
    }
}'
https://api.freshbooks.com/accounting/account/{{accountId}}/bill_vendors/bill_vendors/{{vendorId}}

Postman Collection Item JSON

{
  "name": "Edit Vendor Details",
  "request": {
    "method": "PUT",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"bill_vendor\": {\n        \"vendor_name\": \"IKEA\",\n        \"primary_contact_first_name\": \"Jimmy\",\n        \"primary_contact_last_name\": \"McNamara\",\n        \"primary_contact_email\": \"jimmym@ikea.com\",\n        \"primary_contact\": null,\n        \"street\": \"332 Carlton Ave.\",\n        \"street2\": null,\n        \"city\": \"San Francisco\",\n        \"province\": \"California\",\n        \"postal_code\": null,\n        \"country\": \"United States\",\n        \"account_number\": \"45454545\",\n        \"phone\": \"4158859378\",\n        \"website\": \"ikea.com\",\n        \"currency_code\": \"USD\",\n        \"language\": \"en\",\n        \"is_1099\": false,\n        \"tax_defaults\": []\n    }\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/bill_vendors/bill_vendors/{{vendorId}}",
      "protocol": "https",
      "host": [
        "api",
        "freshbooks",
        "com"
      ],
      "path": [
        "accounting",
        "account",
        "{{accountId}}",
        "bill_vendors",
        "bill_vendors",
        "{{vendorId}}"
      ]
    }
  },
  "response": [
    {
      "name": "Edit Vendor Details",
      "originalRequest": {
        "method": "PUT",
        "header": [
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"bill_vendor\": {\n        \"vendor_name\": \"IKEA\",\n        \"primary_contact_first_name\": \"Jimmy\",\n        \"primary_contact_last_name\": \"McNamara\",\n        \"primary_contact_email\": \"jimmym@ikea.com\",\n        \"primary_contact\": null,\n        \"street\": \"332 Carlton Ave.\",\n        \"street2\": null,\n        \"city\": \"San Francisco\",\n        \"province\": \"California\",\n        \"postal_code\": null,\n        \"country\": \"United States\",\n        \"account_number\": \"45454545\",\n        \"phone\": \"4158859378\",\n        \"website\": \"ikea.com\",\n        \"currency_code\": \"USD\",\n        \"language\": \"en\",\n        \"is_1099\": false,\n        \"tax_defaults\": []\n    }\n}",
          "options": {
            "raw": {
              "language": "json"
            }
          }
        },
        "url": {
          "raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/bill_vendors/bill_vendors/{{vendorId}}",
          "protocol": "https",
          "host": [
            "api",
            "freshbooks",
            "com"
          ],
          "path": [
            "accounting",
            "account",
            "{{accountId}}",
            "bill_vendors",
            "bill_vendors",
            "{{vendorId}}"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "nginx"
        },
        {
          "key": "Date",
          "value": "Fri, 09 Oct 2020 15:39:09 GMT"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "X-NewRelic-App-Data",
          "value": "PxQBWV5TCBABVlVSAwEOVlcTGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4DFVdfRgFPCkNFR0gGWFpfPRAGDFQNShECWl1eXxNcD1UOQUBIBhtRSFUICgJcUFcECA5XUggPAVBKVVYIThpWD11XUAJXXAcHAFdQAFNRQ0oFWV9DATw="
        },
        {
          "key": "X-Frame-Options",
          "value": "SAMEORIGIN"
        },
        {
          "key": "X-XSS-Protection",
          "value": "1; mode=block"
        },
        {
          "key": "X-Content-Type-Options",
          "value": "nosniff"
        },
        {
          "key": "Content-Security-Policy",
          "value": "default-src 'self'"
        },
        {
          "key": "X-Content-Security-Policy",
          "value": "default-src 'self'"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=31556926; includeSubDomains; preload"
        },
        {
          "key": "Referrer-Policy",
          "value": "strict-origin-when-cross-origin"
        },
        {
          "key": "X-RateLimit-Limit",
          "value": "600"
        },
        {
          "key": "X-RateLimit-Remaining",
          "value": "599"
        },
        {
          "key": "X-RateLimit-Reset",
          "value": "1602258010"
        },
        {
          "key": "Retry-After",
          "value": "60"
        },
        {
          "key": "Access-Control-Allow-Origin",
          "value": "*"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "key": "Via",
          "value": "1.1 google"
        },
        {
          "key": "Alt-Svc",
          "value": "h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\""
        },
        {
          "key": "Transfer-Encoding",
          "value": "chunked"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"response\": {\n        \"result\": {\n            \"bill_vendor\": {\n                \"account_number\": \"45454545\",\n                \"city\": \"San Francisco\",\n                \"country\": \"United States\",\n                \"created_at\": \"2020-10-09 15:25:05\",\n                \"currency_code\": \"USD\",\n                \"is_1099\": false,\n                \"language\": \"en\",\n                \"outstanding_balance\": [\n                    {\n                        \"amount\": {\n                            \"amount\": \"450.00\",\n                            \"code\": \"USD\"\n                        }\n                    }\n                ],\n                \"overdue_balance\": [],\n                \"phone\": \"4158859378\",\n                \"postal_code\": null,\n                \"primary_contact_email\": \"jimmym@ikea.com\",\n                \"primary_contact_first_name\": \"Jimmy\",\n                \"primary_contact_last_name\": \"McNamara\",\n                \"province\": \"California\",\n                \"street\": \"332 Carlton Ave.\",\n                \"street2\": null,\n                \"tax_defaults\": [],\n                \"updated_at\": \"2020-10-09 15:39:10\",\n                \"vendor_name\": \"IKEA\",\n                \"vendorid\": 5,\n                \"vis_state\": 0,\n                \"website\": \"ikea.com\"\n            }\n        }\n    }\n}"
    }
  ]
}