Chilkat Online Tools

C++ / New FreshBooks / Single Retainer

Back to Collection Items

#include <CkHttp.h>
#include <CkStringBuilder.h>
#include <CkJsonObject.h>

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

    CkHttp http;
    bool success;

    // Adds the "Authorization: Bearer <access_token>" header.
    http.put_AuthToken("<access_token>");

    CkStringBuilder sbResponseBody;
    success = http.QuickGetSb("https://api.freshbooks.com/comments/business/{{businessId}}/retainer/{{retainerId}}",sbResponseBody);
    if (success == false) {
        std::cout << http.lastErrorText() << "\r\n";
        return;
    }

    CkJsonObject jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    std::cout << "Response Body:" << "\r\n";
    std::cout << jResp.emit() << "\r\n";

    int respStatusCode = http.get_LastStatus();
    std::cout << "Response Status Code = " << respStatusCode << "\r\n";
    if (respStatusCode >= 400) {
        std::cout << "Response Header:" << "\r\n";
        std::cout << http.lastHeader() << "\r\n";
        std::cout << "Failed." << "\r\n";
        return;
    }

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "retainer": {
    //     "id": 2248,
    //     "business_id": 1966214,
    //     "system_id": 4236410,
    //     "invoice_profile_id": null,
    //     "client_user_id": 32046,
    //     "start_date": "2019-06-03",
    //     "next_period_start_date": "2019-06-03",
    //     "fee": "500.00",
    //     "excess_rate": "100.00",
    //     "budgeted_time": 144000,
    //     "active": true,
    //     "created_at": "2019-06-03T15:42:49",
    //     "updated_at": "2019-06-03T15:42:49"
    //   }
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.

    int Id = jResp.IntOf("retainer.id");
    int Business_id = jResp.IntOf("retainer.business_id");
    int System_id = jResp.IntOf("retainer.system_id");
    const char *Invoice_profile_id = jResp.stringOf("retainer.invoice_profile_id");
    int Client_user_id = jResp.IntOf("retainer.client_user_id");
    const char *Start_date = jResp.stringOf("retainer.start_date");
    const char *Next_period_start_date = jResp.stringOf("retainer.next_period_start_date");
    const char *Fee = jResp.stringOf("retainer.fee");
    const char *Excess_rate = jResp.stringOf("retainer.excess_rate");
    int Budgeted_time = jResp.IntOf("retainer.budgeted_time");
    bool Active = jResp.BoolOf("retainer.active");
    const char *Created_at = jResp.stringOf("retainer.created_at");
    const char *Updated_at = jResp.stringOf("retainer.updated_at");
    }

Curl Command

curl -X GET
	-H "Authorization: Bearer <access_token>"
https://api.freshbooks.com/comments/business/{{businessId}}/retainer/{{retainerId}}

Postman Collection Item JSON

{
  "name": "Single Retainer",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "https://api.freshbooks.com/comments/business/{{businessId}}/retainer/{{retainerId}}",
      "protocol": "https",
      "host": [
        "api",
        "freshbooks",
        "com"
      ],
      "path": [
        "comments",
        "business",
        "{{businessId}}",
        "retainer",
        "{{retainerId}}"
      ]
    }
  },
  "response": [
    {
      "name": "Get individual Retainer Retainer ID not found",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.freshbooks.com/comments/business/{{businessId}}/retainer/{{retainerId}}",
          "protocol": "https",
          "host": [
            "api",
            "freshbooks",
            "com"
          ],
          "path": [
            "comments",
            "business",
            "{{businessId}}",
            "retainer",
            "{{retainerId}}"
          ]
        }
      },
      "status": "NOT FOUND",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "nginx"
        },
        {
          "key": "Content-Type",
          "value": "application/vnd.api+json"
        },
        {
          "key": "X-Version",
          "value": "1905.33.0"
        },
        {
          "key": "X-NewRelic-App-Data",
          "value": "PxQBWV5TCBABVllUBAQOU10TGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4AD1lAW0oAEkcLcQoFQl0dFRUEC28DSBIaFAQeA0sJUQNUBVNRAA5TV1AABQdVWVUCHRpXSBMOUlZWB1dSBFsHAVxVBlBcG01XAF8RAWs="
        },
        {
          "key": "X-RateLimit-Limit",
          "value": "20"
        },
        {
          "key": "X-RateLimit-Remaining",
          "value": "0"
        },
        {
          "key": "X-RateLimit-Reset",
          "value": "1559585801"
        },
        {
          "key": "Retry-After",
          "value": "60"
        },
        {
          "key": "Access-Control-Allow-Origin",
          "value": "*"
        },
        {
          "key": "Via",
          "value": "1.1 google"
        },
        {
          "key": "Via",
          "value": "1.1 varnish"
        },
        {
          "key": "Accept-Ranges",
          "value": "bytes"
        },
        {
          "key": "Accept-Ranges",
          "value": "bytes"
        },
        {
          "key": "Age",
          "value": "0"
        },
        {
          "key": "Age",
          "value": "0"
        },
        {
          "key": "Content-Length",
          "value": "135"
        },
        {
          "key": "Date",
          "value": "Mon, 03 Jun 2019 18:15:40 GMT"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "X-Served-By",
          "value": "cache-mdw17376-MDW"
        },
        {
          "key": "X-Cache",
          "value": "MISS"
        },
        {
          "key": "X-Cache-Hits",
          "value": "0"
        },
        {
          "key": "Country",
          "value": "CA"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=31536000; includeSubDomains; preload"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"message\": \"The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.\"\n}"
    },
    {
      "name": "Get individual Retainer success",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.freshbooks.com/comments/business/{{businessId}}/retainer/{{retainerId}}",
          "protocol": "https",
          "host": [
            "api",
            "freshbooks",
            "com"
          ],
          "path": [
            "comments",
            "business",
            "{{businessId}}",
            "retainer",
            "{{retainerId}}"
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "nginx"
        },
        {
          "key": "Content-Type",
          "value": "application/vnd.api+json"
        },
        {
          "key": "X-Version",
          "value": "1905.33.0"
        },
        {
          "key": "X-NewRelic-App-Data",
          "value": "PxQBWV5TCBABVllUBAQOU10TGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4FDFZFVRYSBxlDUhULRERQBxVNEFUWWQtWXUYcQQBKDkQTUAdeRFIVBwpWVkJGTVIbARlXUAkDAldRU1MCWwtbDA0HHh5UFUMIAAEEAlcOVQBWWlYGXFhTFR1RBwhCU24="
        },
        {
          "key": "X-RateLimit-Limit",
          "value": "20"
        },
        {
          "key": "X-RateLimit-Remaining",
          "value": "0"
        },
        {
          "key": "X-RateLimit-Reset",
          "value": "1559585733"
        },
        {
          "key": "Retry-After",
          "value": "55"
        },
        {
          "key": "Access-Control-Allow-Origin",
          "value": "*"
        },
        {
          "key": "Expires",
          "value": "Sun, 03 Jun 2018 18:14:37 GMT"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache"
        },
        {
          "key": "Via",
          "value": "1.1 google"
        },
        {
          "key": "Via",
          "value": "1.1 varnish"
        },
        {
          "key": "Content-Length",
          "value": "350"
        },
        {
          "key": "Accept-Ranges",
          "value": "bytes"
        },
        {
          "key": "Date",
          "value": "Mon, 03 Jun 2019 18:14:37 GMT"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "X-Served-By",
          "value": "cache-mdw17376-MDW"
        },
        {
          "key": "X-Cache",
          "value": "MISS"
        },
        {
          "key": "X-Cache-Hits",
          "value": "0"
        },
        {
          "key": "Country",
          "value": "CA"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=31536000; includeSubDomains; preload"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"retainer\": {\n        \"id\": 2248,\n        \"business_id\": 1966214,\n        \"system_id\": 4236410,\n        \"invoice_profile_id\": null,\n        \"client_user_id\": 32046,\n        \"start_date\": \"2019-06-03\",\n        \"next_period_start_date\": \"2019-06-03\",\n        \"fee\": \"500.00\",\n        \"excess_rate\": \"100.00\",\n        \"budgeted_time\": 144000,\n        \"active\": true,\n        \"created_at\": \"2019-06-03T15:42:49\",\n        \"updated_at\": \"2019-06-03T15:42:49\"\n    }\n}"
    }
  ]
}