Chilkat Online Tools

C++ / New FreshBooks / Share PDF

Back to Collection Items

#include <CkHttp.h>
#include <CkJsonObject.h>
#include <CkHttpResponse.h>
#include <CkStringBuilder.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;

    CkJsonObject queryParams;
    queryParams.UpdateString("share_method","share_link");

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

    CkHttpResponse *resp = http.QuickRequestParams("GET","https://api.freshbooks.com/accounting/account/{{accountId}}/invoices/invoices/{{invoiceId}}/share_link",queryParams);
    if (http.get_LastMethodSuccess() == false) {
        std::cout << http.lastErrorText() << "\r\n";
        return;
    }

    CkStringBuilder sbResponseBody;
    resp->GetBodySb(sbResponseBody);

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

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

    int respStatusCode = resp->get_StatusCode();
    std::cout << "Response Status Code = " << respStatusCode << "\r\n";
    if (respStatusCode >= 400) {
        std::cout << "Response Header:" << "\r\n";
        std::cout << resp->header() << "\r\n";
        std::cout << "Failed." << "\r\n";
        delete resp;
        return;
    }

    delete resp;

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

    // {
    //   "response": {
    //     "result": {
    //       "share_link": {
    //         "clientid": 31006,
    //         "resource_type": "invoice",
    //         "resourceid": "34420",
    //         "share_link": "https://my.freshbooks.com/#/link/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzeXN0ZW1pZCI6NDIzNjQxMCwiYWNjb3VudGlkIjoid2tNZDJnIiwidXNlcmlkIjozMTAwNiwidHlwZSI6Imludm9pY2UiLCJvYmplY3RpZCI6IjM0NDIwIiwiZXhwIjoxNTg3NjY3NTYxLCJsZXZlbCI6MH0.RorQ5sE8moYrKtGcW3O5JkQhzDYgK9XKoYUuX8PHJbA?type=secondary&share_method=share_link",
    //         "share_method": "share_link"
    //       }
    //     }
    //   }
    // }

    // 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 Clientid = jResp.IntOf("response.result.share_link.clientid");
    const char *Resource_type = jResp.stringOf("response.result.share_link.resource_type");
    const char *Resourceid = jResp.stringOf("response.result.share_link.resourceid");
    const char *Share_link = jResp.stringOf("response.result.share_link.share_link");
    const char *Share_method = jResp.stringOf("response.result.share_link.share_method");
    }

Curl Command

curl -G -d "share_method=share_link"
	-H "Authorization: Bearer <access_token>"
https://api.freshbooks.com/accounting/account/{{accountId}}/invoices/invoices/{{invoiceId}}/share_link

Postman Collection Item JSON

{
  "name": "Share PDF",
  "request": {
    "method": "GET",
    "header": [
    ],
    "url": {
      "raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/invoices/invoices/{{invoiceId}}/share_link?share_method=share_link",
      "protocol": "https",
      "host": [
        "api",
        "freshbooks",
        "com"
      ],
      "path": [
        "accounting",
        "account",
        "{{accountId}}",
        "invoices",
        "invoices",
        "{{invoiceId}}",
        "share_link"
      ],
      "query": [
        {
          "key": "share_method",
          "value": "share_link",
          "description": "`share_link`, `email`, `sms`, `pdf` "
        }
      ]
    }
  },
  "response": [
    {
      "name": "Share Link",
      "originalRequest": {
        "method": "GET",
        "header": [
        ],
        "url": {
          "raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/invoices/invoices/{{invoiceId}}/share_link?share_method=share_link",
          "protocol": "https",
          "host": [
            "api",
            "freshbooks",
            "com"
          ],
          "path": [
            "accounting",
            "account",
            "{{accountId}}",
            "invoices",
            "invoices",
            "{{invoiceId}}",
            "share_link"
          ],
          "query": [
            {
              "key": "share_method",
              "value": "share_link",
              "description": "`share_link`, `email`, `sms`, `pdf` "
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Server",
          "value": "nginx"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        },
        {
          "key": "X-NewRelic-App-Data",
          "value": "PxQBWV5TCBABVlVSAwEOVlcTGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4DFVdfRgFPCkNFR0gNX0BcCwUGEQoRUANKXVhbXQ4bTQFNA0xUDwBRV1APAgFdU1sEAwZUXR0bAk5EAFoJAFwBDF5WV1AAAARSWRFOAldbEgM+"
        },
        {
          "key": "Access-Control-Allow-Origin",
          "value": "*"
        },
        {
          "key": "Expires",
          "value": "Tue, 24 Apr 2018 18:46:01 GMT"
        },
        {
          "key": "Cache-Control",
          "value": "no-cache"
        },
        {
          "key": "Content-Encoding",
          "value": "gzip"
        },
        {
          "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": "Transfer-Encoding",
          "value": "chunked"
        },
        {
          "key": "Date",
          "value": "Wed, 24 Apr 2019 18:46:01 GMT"
        },
        {
          "key": "Connection",
          "value": "keep-alive"
        },
        {
          "key": "X-Served-By",
          "value": "cache-mdw17369-MDW"
        },
        {
          "key": "X-Cache",
          "value": "MISS"
        },
        {
          "key": "X-Cache-Hits",
          "value": "0"
        },
        {
          "key": "Vary",
          "value": "Accept-Encoding"
        },
        {
          "key": "Country",
          "value": "CA"
        },
        {
          "key": "Strict-Transport-Security",
          "value": "max-age=31536000; includeSubDomains; preload"
        }
      ],
      "cookie": [
      ],
      "body": "{\n    \"response\": {\n        \"result\": {\n            \"share_link\": {\n                \"clientid\": 31006,\n                \"resource_type\": \"invoice\",\n                \"resourceid\": \"34420\",\n                \"share_link\": \"https://my.freshbooks.com/#/link/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzeXN0ZW1pZCI6NDIzNjQxMCwiYWNjb3VudGlkIjoid2tNZDJnIiwidXNlcmlkIjozMTAwNiwidHlwZSI6Imludm9pY2UiLCJvYmplY3RpZCI6IjM0NDIwIiwiZXhwIjoxNTg3NjY3NTYxLCJsZXZlbCI6MH0.RorQ5sE8moYrKtGcW3O5JkQhzDYgK9XKoYUuX8PHJbA?type=secondary&share_method=share_link\",\n                \"share_method\": \"share_link\"\n            }\n        }\n    }\n}"
    }
  ]
}