C / New FreshBooks / Update Expense with Receipt
Back to Collection Items
#include <C_CkHttp.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>
#include <C_CkHttpResponse.h>
void ChilkatSample(void)
{
HCkHttp http;
BOOL success;
HCkJsonObject json;
HCkStringBuilder sbRequestBody;
HCkHttpResponse resp;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttp_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.
// {
// "expense": {
// "transactionid": null,
// "status": null,
// "has_receipt": false,
// "always_remember": false,
// "is_cogs": false,
// "account_name": null,
// "include_receipt": false,
// "amount": {
// "amount": "79.73",
// "code": "USD"
// },
// "notes": "Purchased Gasoline for deliveries",
// "vendor": "Shell Gas Station",
// "date": "2019-05-23",
// "staffid": 1,
// "author_name": null,
// "taxName1": "other tax",
// "taxName2": null,
// "taxAmount1": {
// "amount": "9.17",
// "code": "USD"
// },
// "taxPercent1": 13,
// "taxPercent2": null,
// "markup_percent": null,
// "invoiceid": null,
// "attachment": {
// "jwt": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhY2NvdW50Ijo0MjM2NDEwLCJvcmlnaW5hbF9maWxlbmFtZSI6IlNjcmVlbiBTaG90IDIwMTktMDQtMjQgYXQgOS4zOS4xOSBBTS5wbmciLCJidWNrZXQiOiJ1cGxvYWRzIiwiZmlsZW5hbWUiOiJ1cGxvYWQtMGU2ZDMwOWQ1ZTI5MzA3NmNhMGIyNDdkODFlOGJlNWE4NDZlZWE0YSIsImxlbmd0aCI6MTkxNDcyLCJrZXkiOiInZG9jcy0nLTQyMzY0MTAvdXBsb2FkLTBlNmQzMDlkNWUyOTMwNzZjYTBiMjQ3ZDgxZThiZTVhODQ2ZWVhNGEifQ.SOoW3_nTUrxjYO76g1UXHPIrO_aLbTpXCHEa-ZcnejA",
// "media_type": "image/png",
// "expenseid": null
// },
// "categoryid": "2003174",
// "clientid": null
// }
// }
json = CkJsonObject_Create();
CkJsonObject_UpdateNull(json,"expense.transactionid");
CkJsonObject_UpdateNull(json,"expense.status");
CkJsonObject_UpdateBool(json,"expense.has_receipt",FALSE);
CkJsonObject_UpdateBool(json,"expense.always_remember",FALSE);
CkJsonObject_UpdateBool(json,"expense.is_cogs",FALSE);
CkJsonObject_UpdateNull(json,"expense.account_name");
CkJsonObject_UpdateBool(json,"expense.include_receipt",FALSE);
CkJsonObject_UpdateString(json,"expense.amount.amount","79.73");
CkJsonObject_UpdateString(json,"expense.amount.code","USD");
CkJsonObject_UpdateString(json,"expense.notes","Purchased Gasoline for deliveries");
CkJsonObject_UpdateString(json,"expense.vendor","Shell Gas Station");
CkJsonObject_UpdateString(json,"expense.date","2019-05-23");
CkJsonObject_UpdateInt(json,"expense.staffid",1);
CkJsonObject_UpdateNull(json,"expense.author_name");
CkJsonObject_UpdateString(json,"expense.taxName1","other tax");
CkJsonObject_UpdateNull(json,"expense.taxName2");
CkJsonObject_UpdateString(json,"expense.taxAmount1.amount","9.17");
CkJsonObject_UpdateString(json,"expense.taxAmount1.code","USD");
CkJsonObject_UpdateInt(json,"expense.taxPercent1",13);
CkJsonObject_UpdateNull(json,"expense.taxPercent2");
CkJsonObject_UpdateNull(json,"expense.markup_percent");
CkJsonObject_UpdateNull(json,"expense.invoiceid");
CkJsonObject_UpdateString(json,"expense.attachment.jwt","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhY2NvdW50Ijo0MjM2NDEwLCJvcmlnaW5hbF9maWxlbmFtZSI6IlNjcmVlbiBTaG90IDIwMTktMDQtMjQgYXQgOS4zOS4xOSBBTS5wbmciLCJidWNrZXQiOiJ1cGxvYWRzIiwiZmlsZW5hbWUiOiJ1cGxvYWQtMGU2ZDMwOWQ1ZTI5MzA3NmNhMGIyNDdkODFlOGJlNWE4NDZlZWE0YSIsImxlbmd0aCI6MTkxNDcyLCJrZXkiOiInZG9jcy0nLTQyMzY0MTAvdXBsb2FkLTBlNmQzMDlkNWUyOTMwNzZjYTBiMjQ3ZDgxZThiZTVhODQ2ZWVhNGEifQ.SOoW3_nTUrxjYO76g1UXHPIrO_aLbTpXCHEa-ZcnejA");
CkJsonObject_UpdateString(json,"expense.attachment.media_type","image/png");
CkJsonObject_UpdateNull(json,"expense.attachment.expenseid");
CkJsonObject_UpdateString(json,"expense.categoryid","2003174");
CkJsonObject_UpdateNull(json,"expense.clientid");
// Adds the "Authorization: Bearer <access_token>" header.
CkHttp_putAuthToken(http,"<access_token>");
CkHttp_SetRequestHeader(http,"Content-Type","application/json");
sbRequestBody = CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);
resp = CkHttp_PTextSb(http,"PUT","https://api.freshbooks.com/accounting/account/{{accountId}}/expenses/expenses/{{expenseId}}?include%5B%5D=attachment",sbRequestBody,"utf-8","application/json",FALSE,FALSE);
if (CkHttp_getLastMethodSuccess(http) == FALSE) {
printf("%s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
return;
}
printf("%d\n",CkHttpResponse_getStatusCode(resp));
printf("%s\n",CkHttpResponse_bodyStr(resp));
CkHttpResponse_Dispose(resp);
CkHttp_Dispose(http);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
}
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
-H "Content-Type: application/json"
-d '{
"expense": {
"transactionid": null,
"status": null,
"has_receipt": false,
"always_remember": false,
"is_cogs": false,
"account_name": null,
"include_receipt": false,
"amount": {
"amount": "79.73",
"code": "USD"
},
"notes": "Purchased Gasoline for deliveries",
"vendor": "Shell Gas Station",
"date": "2019-05-23",
"staffid": 1,
"author_name": null,
"taxName1": "other tax",
"taxName2": null,
"taxAmount1": {
"amount": "9.17",
"code": "USD"
},
"taxPercent1": 13,
"taxPercent2": null,
"markup_percent": null,
"invoiceid": null,
"attachment": {
"jwt": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhY2NvdW50Ijo0MjM2NDEwLCJvcmlnaW5hbF9maWxlbmFtZSI6IlNjcmVlbiBTaG90IDIwMTktMDQtMjQgYXQgOS4zOS4xOSBBTS5wbmciLCJidWNrZXQiOiJ1cGxvYWRzIiwiZmlsZW5hbWUiOiJ1cGxvYWQtMGU2ZDMwOWQ1ZTI5MzA3NmNhMGIyNDdkODFlOGJlNWE4NDZlZWE0YSIsImxlbmd0aCI6MTkxNDcyLCJrZXkiOiInZG9jcy0nLTQyMzY0MTAvdXBsb2FkLTBlNmQzMDlkNWUyOTMwNzZjYTBiMjQ3ZDgxZThiZTVhODQ2ZWVhNGEifQ.SOoW3_nTUrxjYO76g1UXHPIrO_aLbTpXCHEa-ZcnejA",
"media_type": "image/png",
"expenseid": null
},
"categoryid": "2003174",
"clientid": null
}
}'
https://api.freshbooks.com/accounting/account/{{accountId}}/expenses/expenses/{{expenseId}}?include%5B%5D=attachment
Postman Collection Item JSON
{
"name": "Update Expense with Receipt",
"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"expense\": {\n \"transactionid\": null,\n \"status\": null,\n \"has_receipt\": false,\n \"always_remember\": false,\n \"is_cogs\": false,\n \"account_name\": null,\n \"include_receipt\": false,\n \"amount\": {\n \"amount\": \"79.73\",\n \"code\": \"USD\"\n },\n \"notes\": \"Purchased Gasoline for deliveries\",\n \"vendor\": \"Shell Gas Station\",\n \"date\": \"2019-05-23\",\n \"staffid\": 1,\n \"author_name\": null,\n \"taxName1\": \"other tax\",\n \"taxName2\": null,\n \"taxAmount1\": {\n \"amount\": \"9.17\",\n \"code\": \"USD\"\n },\n \"taxPercent1\": 13,\n \"taxPercent2\": null,\n \"markup_percent\": null,\n \"invoiceid\": null,\n \"attachment\": {\n \"jwt\": \"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhY2NvdW50Ijo0MjM2NDEwLCJvcmlnaW5hbF9maWxlbmFtZSI6IlNjcmVlbiBTaG90IDIwMTktMDQtMjQgYXQgOS4zOS4xOSBBTS5wbmciLCJidWNrZXQiOiJ1cGxvYWRzIiwiZmlsZW5hbWUiOiJ1cGxvYWQtMGU2ZDMwOWQ1ZTI5MzA3NmNhMGIyNDdkODFlOGJlNWE4NDZlZWE0YSIsImxlbmd0aCI6MTkxNDcyLCJrZXkiOiInZG9jcy0nLTQyMzY0MTAvdXBsb2FkLTBlNmQzMDlkNWUyOTMwNzZjYTBiMjQ3ZDgxZThiZTVhODQ2ZWVhNGEifQ.SOoW3_nTUrxjYO76g1UXHPIrO_aLbTpXCHEa-ZcnejA\",\n \"media_type\": \"image/png\",\n \"expenseid\": null\n },\n \"categoryid\": \"2003174\",\n \"clientid\": null\n }\n}"
},
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/expenses/expenses/{{expenseId}}?include%5B%5D=attachment",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"expenses",
"expenses",
"{{expenseId}}"
],
"query": [
{
"key": "include%5B%5D",
"value": "attachment"
}
]
}
},
"response": [
]
}