Chilkat Online Tools

unicodeC / New FreshBooks / Create Recurring Expense

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.

    // {
    //   "expense_profile": {
    //     "frequency": "m",
    //     "profileid": null,
    //     "start_date": "2019-01-13",
    //     "end_date": null,
    //     "next_issue_date": "2019-01-13",
    //     "is_cogs": false,
    //     "amount": {
    //       "amount": "100",
    //       "code": "CAD"
    //     },
    //     "notes": null,
    //     "vendor": "Recurring Expenses Inc.",
    //     "staffid": 1,
    //     "author_name": null,
    //     "taxName1": "HST",
    //     "taxName2": null,
    //     "taxAmount1": {
    //       "amount": "11.5",
    //       "code": "CAD"
    //     },
    //     "taxPercent1": 13,
    //     "taxPercent2": null,
    //     "markup_percent": null,
    //     "from_bulk_import": false,
    //     "categoryid": "4723650",
    //     "clientid": null
    //   }
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"expense_profile.frequency",L"m");
    CkJsonObjectW_UpdateNull(json,L"expense_profile.profileid");
    CkJsonObjectW_UpdateString(json,L"expense_profile.start_date",L"2019-01-13");
    CkJsonObjectW_UpdateNull(json,L"expense_profile.end_date");
    CkJsonObjectW_UpdateString(json,L"expense_profile.next_issue_date",L"2019-01-13");
    CkJsonObjectW_UpdateBool(json,L"expense_profile.is_cogs",FALSE);
    CkJsonObjectW_UpdateString(json,L"expense_profile.amount.amount",L"100");
    CkJsonObjectW_UpdateString(json,L"expense_profile.amount.code",L"CAD");
    CkJsonObjectW_UpdateNull(json,L"expense_profile.notes");
    CkJsonObjectW_UpdateString(json,L"expense_profile.vendor",L"Recurring Expenses Inc.");
    CkJsonObjectW_UpdateInt(json,L"expense_profile.staffid",1);
    CkJsonObjectW_UpdateNull(json,L"expense_profile.author_name");
    CkJsonObjectW_UpdateString(json,L"expense_profile.taxName1",L"HST");
    CkJsonObjectW_UpdateNull(json,L"expense_profile.taxName2");
    CkJsonObjectW_UpdateString(json,L"expense_profile.taxAmount1.amount",L"11.5");
    CkJsonObjectW_UpdateString(json,L"expense_profile.taxAmount1.code",L"CAD");
    CkJsonObjectW_UpdateInt(json,L"expense_profile.taxPercent1",13);
    CkJsonObjectW_UpdateNull(json,L"expense_profile.taxPercent2");
    CkJsonObjectW_UpdateNull(json,L"expense_profile.markup_percent");
    CkJsonObjectW_UpdateBool(json,L"expense_profile.from_bulk_import",FALSE);
    CkJsonObjectW_UpdateString(json,L"expense_profile.categoryid",L"4723650");
    CkJsonObjectW_UpdateNull(json,L"expense_profile.clientid");

    // 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}}/expense_profiles/expense_profiles",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 '{
    "expense_profile": {
        "frequency": "m",
        "profileid": null,
        "start_date": "2019-01-13",
        "end_date": null,
        "next_issue_date": "2019-01-13",
        "is_cogs": false,
        "amount": {
            "amount": "100",
            "code": "CAD"
        },
        "notes": null,
        "vendor": "Recurring Expenses Inc.",
        "staffid": 1,
        "author_name": null,
        "taxName1": "HST",
        "taxName2": null,
        "taxAmount1": {
            "amount": "11.5",
            "code": "CAD"
        },
        "taxPercent1": 13,
        "taxPercent2": null,
        "markup_percent": null,
        "from_bulk_import": false,
        "categoryid": "4723650",
        "clientid": null
    }
}'
https://api.freshbooks.com/accounting/account/{{accountid}}/expense_profiles/expense_profiles

Postman Collection Item JSON

{
  "name": "Create Recurring Expense",
  "request": {
    "method": "POST",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "value": "application/json",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"expense_profile\": {\n        \"frequency\": \"m\",\n        \"profileid\": null,\n        \"start_date\": \"2019-01-13\",\n        \"end_date\": null,\n        \"next_issue_date\": \"2019-01-13\",\n        \"is_cogs\": false,\n        \"amount\": {\n            \"amount\": \"100\",\n            \"code\": \"CAD\"\n        },\n        \"notes\": null,\n        \"vendor\": \"Recurring Expenses Inc.\",\n        \"staffid\": 1,\n        \"author_name\": null,\n        \"taxName1\": \"HST\",\n        \"taxName2\": null,\n        \"taxAmount1\": {\n            \"amount\": \"11.5\",\n            \"code\": \"CAD\"\n        },\n        \"taxPercent1\": 13,\n        \"taxPercent2\": null,\n        \"markup_percent\": null,\n        \"from_bulk_import\": false,\n        \"categoryid\": \"4723650\",\n        \"clientid\": null\n    }\n}"
    },
    "url": {
      "raw": "https://api.freshbooks.com/accounting/account/{{accountid}}/expense_profiles/expense_profiles",
      "protocol": "https",
      "host": [
        "api",
        "freshbooks",
        "com"
      ],
      "path": [
        "accounting",
        "account",
        "{{accountid}}",
        "expense_profiles",
        "expense_profiles"
      ]
    }
  },
  "response": [
  ]
}