Chilkat Online Tools

unicodeCpp / New FreshBooks / Update Tax

Back to Collection Items

#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
#include <CkHttpResponseW.h>

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

    CkHttpW http;
    bool success;

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

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

    // {
    //   "tax": {
    //     "name": "HST",
    //     "number": null,
    //     "amount": 13
    //   }
    // }

    CkJsonObjectW json;
    json.UpdateString(L"tax.name",L"HST");
    json.UpdateNull(L"tax.number");
    json.UpdateInt(L"tax.amount",13);

    // Adds the "Authorization: Bearer <access_token>" header.
    http.put_AuthToken(L"<access_token>");
    http.SetRequestHeader(L"Content-Type",L"application/json");

    CkStringBuilderW sbRequestBody;
    json.EmitSb(sbRequestBody);

    CkHttpResponseW *resp = http.PTextSb(L"PUT",L"https://api.freshbooks.com/accounting/account/{{accountid}}/taxes/taxes/{{taxid}}",sbRequestBody,L"utf-8",L"application/json",false,false);
    if (http.get_LastMethodSuccess() == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    wprintf(L"%d\n",resp->get_StatusCode());
    wprintf(L"%s\n",resp->bodyStr());
    delete resp;
    }

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
    "tax": {
        "name": "HST",
        "number": null,
        "amount": 13
    }
}'
https://api.freshbooks.com/accounting/account/{{accountid}}/taxes/taxes/{{taxid}}

Postman Collection Item JSON

{
  "name": "Update Tax",
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "type": "text",
        "value": "application/json"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"tax\": {\n        \"name\": \"HST\",\n        \"number\": null,\n        \"amount\": 13\n    }\n}"
    },
    "url": {
      "raw": "https://api.freshbooks.com/accounting/account/{{accountid}}/taxes/taxes/{{taxid}}",
      "protocol": "https",
      "host": [
        "api",
        "freshbooks",
        "com"
      ],
      "path": [
        "accounting",
        "account",
        "{{accountid}}",
        "taxes",
        "taxes",
        "{{taxid}}"
      ]
    }
  },
  "response": [
  ]
}