Chilkat Online Tools

delphiDll / New FreshBooks / Share PDF

Back to Collection Items

var
http: HCkHttp;
success: Boolean;
queryParams: HCkJsonObject;
resp: HCkHttpResponse;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
Clientid: Integer;
Resource_type: PWideChar;
Resourceid: PWideChar;
Share_link: PWideChar;
Share_method: PWideChar;

begin
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

http := CkHttp_Create();

queryParams := CkJsonObject_Create();
CkJsonObject_UpdateString(queryParams,'share_method','share_link');

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

resp := CkHttp_QuickRequestParams(http,'GET','https://api.freshbooks.com/accounting/account/{{accountId}}/invoices/invoices/{{invoiceId}}/share_link',queryParams);
if (CkHttp_getLastMethodSuccess(http) = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

sbResponseBody := CkStringBuilder_Create();
CkHttpResponse_GetBodySb(resp,sbResponseBody);

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttpResponse_getStatusCode(resp);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttpResponse__header(resp));
    Memo1.Lines.Add('Failed.');
    CkHttpResponse_Dispose(resp);
    Exit;
  end;
CkHttpResponse_Dispose(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

Clientid := CkJsonObject_IntOf(jResp,'response.result.share_link.clientid');
Resource_type := CkJsonObject__stringOf(jResp,'response.result.share_link.resource_type');
Resourceid := CkJsonObject__stringOf(jResp,'response.result.share_link.resourceid');
Share_link := CkJsonObject__stringOf(jResp,'response.result.share_link.share_link');
Share_method := CkJsonObject__stringOf(jResp,'response.result.share_link.share_method');

CkHttp_Dispose(http);
CkJsonObject_Dispose(queryParams);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

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}"
    }
  ]
}