unicodeC / New FreshBooks / Create Single Tax
Back to Collection Items
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
HCkHttpW http;
BOOL success;
HCkJsonObjectW json;
HCkHttpResponseW resp;
// 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.
// {
// "tax": {
// "name": "HST",
// "number": null,
// "amount": 13
// }
// }
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"tax.name",L"HST");
CkJsonObjectW_UpdateNull(json,L"tax.number");
CkJsonObjectW_UpdateInt(json,L"tax.amount",13);
// Adds the "Authorization: Bearer <access_token>" header.
CkHttpW_putAuthToken(http,L"<access_token>");
CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json");
resp = CkHttpW_PostJson3(http,L"https://api.freshbooks.com/accounting/account/{{accountid}}/taxes/taxes",L"application/json",json);
if (CkHttpW_getLastMethodSuccess(http) == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
return;
}
wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
CkHttpResponseW_Dispose(resp);
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(json);
}
Curl Command
curl -X POST
-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
Postman Collection Item JSON
{
"name": "Create Single Tax",
"request": {
"auth": {
"type": "oauth2",
"oauth2": [
{
"key": "accessToken",
"value": "",
"type": "string"
},
{
"key": "addTokenTo",
"value": "header",
"type": "string"
}
]
},
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"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",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountid}}",
"taxes",
"taxes"
]
}
},
"response": [
]
}