Chilkat Online Tools

delphiAx / New FreshBooks / Delete Retainer

Back to Collection Items

var
http: TChilkatHttp;
success: Integer;
json: TChilkatJsonObject;
sbRequestBody: TChilkatStringBuilder;
resp: IChilkatHttpResponse;
sbResponseBody: TChilkatStringBuilder;
jResp: TChilkatJsonObject;
respStatusCode: Integer;
Id: Integer;
Business_id: Integer;
System_id: Integer;
Invoice_profile_id: WideString;
Client_user_id: Integer;
Start_date: WideString;
Next_period_start_date: WideString;
Fee: WideString;
Excess_rate: WideString;
Budgeted_time: Integer;
Active: Integer;
Created_at: WideString;
Updated_at: WideString;

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

http := TChilkatHttp.Create(Self);

// Use this online tool to generate code from sample JSON: Generate Code to Create JSON

// The following JSON is sent in the request body.

// {
//   "retainer": {
//     "active": false
//   }
// }

json := TChilkatJsonObject.Create(Self);
json.UpdateBool('retainer.active',0);

// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken := '<access_token>';
http.SetRequestHeader('Content-Type','application/json');

sbRequestBody := TChilkatStringBuilder.Create(Self);
json.EmitSb(sbRequestBody.ControlInterface);

resp := http.PTextSb('PUT','https://api.freshbooks.com/comments/business/{{businessId}}/retainer/{{retainerId}}',sbRequestBody.ControlInterface,'utf-8','application/json',0,0);
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)

// {
//   "retainer": {
//     "id": 2248,
//     "business_id": 1966214,
//     "system_id": 4236410,
//     "invoice_profile_id": null,
//     "client_user_id": 75162,
//     "start_date": "2019-06-03",
//     "next_period_start_date": "2019-07-03",
//     "fee": "20.00",
//     "excess_rate": "700.00",
//     "budgeted_time": 180000,
//     "active": false,
//     "created_at": "2019-06-03T15:42:49",
//     "updated_at": "2019-06-03T18:22:53"
//   }
// }

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

Id := jResp.IntOf('retainer.id');
Business_id := jResp.IntOf('retainer.business_id');
System_id := jResp.IntOf('retainer.system_id');
Invoice_profile_id := jResp.StringOf('retainer.invoice_profile_id');
Client_user_id := jResp.IntOf('retainer.client_user_id');
Start_date := jResp.StringOf('retainer.start_date');
Next_period_start_date := jResp.StringOf('retainer.next_period_start_date');
Fee := jResp.StringOf('retainer.fee');
Excess_rate := jResp.StringOf('retainer.excess_rate');
Budgeted_time := jResp.IntOf('retainer.budgeted_time');
Active := jResp.BoolOf('retainer.active');
Created_at := jResp.StringOf('retainer.created_at');
Updated_at := jResp.StringOf('retainer.updated_at');

Curl Command

curl -X PUT
	-H "Authorization: Bearer <access_token>"
	-H "Content-Type: application/json"
	-d '{
    "retainer": {
        "active": false
    }
}'
https://api.freshbooks.com/comments/business/{{businessId}}/retainer/{{retainerId}}

Postman Collection Item JSON

{
  "name": "Delete Retainer",
  "request": {
    "method": "PUT",
    "header": [
      {
        "key": "Content-Type",
        "name": "Content-Type",
        "value": "application/json",
        "type": "text"
      }
    ],
    "body": {
      "mode": "raw",
      "raw": "{\n    \"retainer\": {\n        \"active\": false\n    }\n}"
    },
    "url": {
      "raw": "https://api.freshbooks.com/comments/business/{{businessId}}/retainer/{{retainerId}}",
      "protocol": "https",
      "host": [
        "api",
        "freshbooks",
        "com"
      ],
      "path": [
        "comments",
        "business",
        "{{businessId}}",
        "retainer",
        "{{retainerId}}"
      ]
    },
    "description": "A retainer is deleted by changing the active status to \"false\". It can be undeleted by changing active status back to true."
  },
  "response": [
    {
      "name": "Delete Retainer Success",
      "originalRequest": {
        "method": "PUT",
        "header": [
          {
            "key": "Content-Type",
            "name": "Content-Type",
            "value": "application/json",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\n    \"retainer\": {\n        \"active\": false\n    }\n}"
        },
        "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": "PxQBWV5TCBABVllUBAQOU10TGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4FDFZFVRYSBxlDUhULRERQBxVNEFUWWQtWXUYcQQBKDkQTUAdeRFIVBwpWVkJGTVIbARlXVgQCClFWV1sGUAlXAAoEAR9QCE0TAwtWVgNWVVYACFcAXQdaBhMbAAVdRVY/"
        },
        {
          "key": "X-RateLimit-Limit",
          "value": "20"
        },
        {
          "key": "X-RateLimit-Remaining",
          "value": "0"
        },
        {
          "key": "X-RateLimit-Reset",
          "value": "1559586233"
        },
        {
          "key": "Retry-After",
          "value": "59"
        },
        {
          "key": "Access-Control-Allow-Origin",
          "value": "*"
        },
        {
          "key": "Expires",
          "value": "Sun, 03 Jun 2018 18:22:53 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:22:53 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\": 75162,\n        \"start_date\": \"2019-06-03\",\n        \"next_period_start_date\": \"2019-07-03\",\n        \"fee\": \"20.00\",\n        \"excess_rate\": \"700.00\",\n        \"budgeted_time\": 180000,\n        \"active\": false,\n        \"created_at\": \"2019-06-03T15:42:49\",\n        \"updated_at\": \"2019-06-03T18:22:53\"\n    }\n}"
    }
  ]
}