Chilkat Online Tools

unicodeC / New FreshBooks / Update Checkout Link

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;

    // 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.

    // {
    //   "item_id": "147778",
    //   "amount": "100",
    //   "currency": "CAD",
    //   "note": "Thank you for your Business",
    //   "is_active": false,
    //   "send_admin_receipt": true,
    //   "taxes": [
    //     {
    //       "name": "HST",
    //       "amount": 13
    //     }
    //   ],
    //   "item_name": "The Best Doorknob"
    // }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"item_id",L"147778");
    CkJsonObjectW_UpdateString(json,L"amount",L"100");
    CkJsonObjectW_UpdateString(json,L"currency",L"CAD");
    CkJsonObjectW_UpdateString(json,L"note",L"Thank you for your Business");
    CkJsonObjectW_UpdateBool(json,L"is_active",FALSE);
    CkJsonObjectW_UpdateBool(json,L"send_admin_receipt",TRUE);
    CkJsonObjectW_UpdateString(json,L"taxes[0].name",L"HST");
    CkJsonObjectW_UpdateInt(json,L"taxes[0].amount",13);
    CkJsonObjectW_UpdateString(json,L"item_name",L"The Best Doorknob");

    // 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/payments/account/{{accountid}}/checkout-links/{{checkoutlinkid}}",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;
    }

    wprintf(L"%d\n",CkHttpResponseW_getStatusCode(resp));
    wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp));
    CkHttpResponseW_Dispose(resp);


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

    }

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-d '{
    "item_id": "147778",
    "amount": "100",
    "currency": "CAD",
    "note": "Thank you for your Business",
    "is_active": false,
    "send_admin_receipt": true,
    "taxes": [{"name":"HST","amount":13}],
    "item_name": "The Best Doorknob"
}'
https://api.freshbooks.com/payments/account/{{accountid}}/checkout-links/{{checkoutlinkid}}

Postman Collection Item JSON

{
  "name": "Update Checkout Link",
  "request": {
    "method": "PUT",
    "header": [
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"item_id\": \"147778\",\n    \"amount\": \"100\",\n    \"currency\": \"CAD\",\n    \"note\": \"Thank you for your Business\",\n    \"is_active\": false,\n    \"send_admin_receipt\": true,\n    \"taxes\": [{\"name\":\"HST\",\"amount\":13}],\n    \"item_name\": \"The Best Doorknob\"\n}",
      "options": {
        "raw": {
          "language": "json"
        }
      }
    },
    "url": {
      "raw": "https://api.freshbooks.com/payments/account/{{accountid}}/checkout-links/{{checkoutlinkid}}",
      "protocol": "https",
      "host": [
        "api",
        "freshbooks",
        "com"
      ],
      "path": [
        "payments",
        "account",
        "{{accountid}}",
        "checkout-links",
        "{{checkoutlinkid}}"
      ]
    }
  },
  "response": [
  ]
}