Back to Collection Items
var
http: TChilkatHttp;
success: Integer;
queryParams: TChilkatJsonObject;
resp: IChilkatHttpResponse;
sbResponseBody: TChilkatStringBuilder;
jResp: TChilkatJsonObject;
respStatusCode: Integer;
Clientid: Integer;
Resource_type: WideString;
Resourceid: WideString;
Share_link: WideString;
Share_method: WideString;
begin
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := TChilkatHttp.Create(Self);
queryParams := TChilkatJsonObject.Create(Self);
queryParams.UpdateString('share_method','share_link');
// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken := '<access_token>';
resp := http.QuickRequestParams('GET','https://api.freshbooks.com/accounting/account/{{accountId}}/invoices/invoices/{{invoiceId}}/share_link',queryParams.ControlInterface);
if (http.LastMethodSuccess = 0) then
begin
Memo1.Lines.Add(http.LastErrorText);
Exit;
end;
sbResponseBody := TChilkatStringBuilder.Create(Self);
resp.GetBodySb(sbResponseBody.ControlInterface);
jResp := TChilkatJsonObject.Create(Self);
jResp.LoadSb(sbResponseBody.ControlInterface);
jResp.EmitCompact := 0;
Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(jResp.Emit());
respStatusCode := resp.StatusCode;
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
begin
Memo1.Lines.Add('Response Header:');
Memo1.Lines.Add(resp.Header);
Memo1.Lines.Add('Failed.');
Exit;
end;
// 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 := jResp.IntOf('response.result.share_link.clientid');
Resource_type := jResp.StringOf('response.result.share_link.resource_type');
Resourceid := jResp.StringOf('response.result.share_link.resourceid');
Share_link := jResp.StringOf('response.result.share_link.share_link');
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}"
}
]
}