Back to Collection Items
var os = require('os');
if (os.platform() == 'win32') {
if (os.arch() == 'ia32') {
var chilkat = require('@chilkat/ck-node21-win-ia32');
} else {
var chilkat = require('@chilkat/ck-node21-win64');
}
} else if (os.platform() == 'linux') {
if (os.arch() == 'arm') {
var chilkat = require('@chilkat/ck-node21-arm');
} else if (os.arch() == 'x86') {
var chilkat = require('@chilkat/ck-node21-linux32');
} else {
var chilkat = require('@chilkat/ck-node21-linux64');
}
} else if (os.platform() == 'darwin') {
if (os.arch() == 'arm64') {
var chilkat = require('@chilkat/ck-node21-mac-m1');
} else {
var chilkat = require('@chilkat/ck-node21-macosx');
}
}
function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
var http = new chilkat.Http();
var success;
// 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": {
// "client_user_id": "32040",
// "start_date": "2019-06-05",
// "next_period_start_date": "2019-06-03",
// "fee": 600,
// "excess_rate": 200,
// "budgeted_time": 144000,
// "active": true,
// "frequency": "m",
// "number_recurring": 0,
// "is_infinitely_recurring": true
// }
// }
var json = new chilkat.JsonObject();
json.UpdateString("retainer.client_user_id","32040");
json.UpdateString("retainer.start_date","2019-06-05");
json.UpdateString("retainer.next_period_start_date","2019-06-03");
json.UpdateInt("retainer.fee",600);
json.UpdateInt("retainer.excess_rate",200);
json.UpdateInt("retainer.budgeted_time",144000);
json.UpdateBool("retainer.active",true);
json.UpdateString("retainer.frequency","m");
json.UpdateInt("retainer.number_recurring",0);
json.UpdateBool("retainer.is_infinitely_recurring",true);
// Adds the "Authorization: Bearer <access_token>" header.
http.AuthToken = "<access_token>";
http.SetRequestHeader("Content-Type","application/json");
// resp: HttpResponse
var resp = http.PostJson3("https://api.freshbooks.com/comments/business/{{businessId}}/retainers","application/json",json);
if (http.LastMethodSuccess == false) {
console.log(http.LastErrorText);
return;
}
var sbResponseBody = new chilkat.StringBuilder();
resp.GetBodySb(sbResponseBody);
var jResp = new chilkat.JsonObject();
jResp.LoadSb(sbResponseBody);
jResp.EmitCompact = false;
console.log("Response Body:");
console.log(jResp.Emit());
var respStatusCode = resp.StatusCode;
console.log("Response Status Code = " + respStatusCode);
if (respStatusCode >= 400) {
console.log("Response Header:");
console.log(resp.Header);
console.log("Failed.");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "retainer": {
// "id": 2274,
// "business_id": 1966214,
// "system_id": 4236410,
// "invoice_profile_id": null,
// "client_user_id": 32040,
// "start_date": "2019-06-05",
// "next_period_start_date": "2019-06-03",
// "fee": "600.00",
// "excess_rate": "200.00",
// "budgeted_time": 144000,
// "active": true,
// "created_at": "2019-06-03T18:11:26",
// "updated_at": "2019-06-03T18:11:26"
// }
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
var Id = jResp.IntOf("retainer.id");
var Business_id = jResp.IntOf("retainer.business_id");
var System_id = jResp.IntOf("retainer.system_id");
var Invoice_profile_id = jResp.StringOf("retainer.invoice_profile_id");
var Client_user_id = jResp.IntOf("retainer.client_user_id");
var Start_date = jResp.StringOf("retainer.start_date");
var Next_period_start_date = jResp.StringOf("retainer.next_period_start_date");
var Fee = jResp.StringOf("retainer.fee");
var Excess_rate = jResp.StringOf("retainer.excess_rate");
var Budgeted_time = jResp.IntOf("retainer.budgeted_time");
var Active = jResp.BoolOf("retainer.active");
var Created_at = jResp.StringOf("retainer.created_at");
var Updated_at = jResp.StringOf("retainer.updated_at");
}
chilkatExample();
Curl Command
curl -X POST
-H "Authorization: Bearer <access_token>"
-H "Content-Type: application/json"
-d '{
"retainer": {
"client_user_id": "32040",
"start_date": "2019-06-05",
"next_period_start_date": "2019-06-03",
"fee": 600,
"excess_rate": 200,
"budgeted_time": 144000,
"active": true,
"frequency": "m",
"number_recurring": 0,
"is_infinitely_recurring": true
}
}'
https://api.freshbooks.com/comments/business/{{businessId}}/retainers
Postman Collection Item JSON
{
"name": "Create Retainer",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"retainer\": {\n \"client_user_id\": \"32040\",\n \"start_date\": \"2019-06-05\",\n \"next_period_start_date\": \"2019-06-03\",\n \"fee\": 600,\n \"excess_rate\": 200,\n \"budgeted_time\": 144000,\n \"active\": true,\n \"frequency\": \"m\",\n \"number_recurring\": 0,\n \"is_infinitely_recurring\": true\n }\n}"
},
"url": {
"raw": "https://api.freshbooks.com/comments/business/{{businessId}}/retainers",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"comments",
"business",
"{{businessId}}",
"retainers"
]
}
},
"response": [
{
"name": "Create Retainer Retainer for client already exists",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"retainer\": {\n \"client_user_id\": \"32040\",\n \"start_date\": \"2019-06-05\",\n \"next_period_start_date\": \"2019-06-03\",\n \"fee\": 600,\n \"excess_rate\": 200,\n \"budgeted_time\": 144000,\n \"active\": true,\n \"frequency\": \"m\",\n \"number_recurring\": 0,\n \"is_infinitely_recurring\": true\n }\n}"
},
"url": {
"raw": "https://api.freshbooks.com/comments/business/{{businessId}}/retainers",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"comments",
"business",
"{{businessId}}",
"retainers"
]
}
},
"status": "UNPROCESSABLE ENTITY",
"code": 422,
"_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": "PxQBWV5TCBABVllUBAQOU10TGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4FDFZFVRYSBxlDUhULRERQBxVNEFUWWQtWXUYcQQBKDkQTUAdeRFIVBwpWVkJGTVIbARlWXQEPClRTU1EIUAFbDQ4EBx9WDVkdQwMHBgdTAgdSWgFUBQdTBwkVSgJQWkAHOw=="
},
{
"key": "X-RateLimit-Limit",
"value": "20"
},
{
"key": "X-RateLimit-Remaining",
"value": "0"
},
{
"key": "X-RateLimit-Reset",
"value": "1559585586"
},
{
"key": "Retry-After",
"value": "57"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Via",
"value": "1.1 google"
},
{
"key": "Via",
"value": "1.1 varnish"
},
{
"key": "Content-Length",
"value": "62"
},
{
"key": "Accept-Ranges",
"value": "bytes"
},
{
"key": "Date",
"value": "Mon, 03 Jun 2019 18:12:08 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 \"errno\": 2001,\n \"error\": \"Retainer for client already exists\"\n}"
},
{
"name": "Create Retainer Success",
"originalRequest": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/json",
"type": "text"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"retainer\": {\n \"client_user_id\": \"32040\",\n \"start_date\": \"2019-06-05\",\n \"next_period_start_date\": \"2019-06-03\",\n \"fee\": 600,\n \"excess_rate\": 200,\n \"budgeted_time\": 144000,\n \"active\": true,\n \"frequency\": \"m\",\n \"number_recurring\": 0,\n \"is_infinitely_recurring\": true\n }\n}"
},
"url": {
"raw": "https://api.freshbooks.com/comments/business/{{businessId}}/retainers",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"comments",
"business",
"{{businessId}}",
"retainers"
]
}
},
"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": "PxQBWV5TCBABVllUBAQOU10TGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4FDFZFVRYSBxlDUhULRERQBxVNEFUWWQtWXUYcQQBKDkQTUAdeRFIVBwpWVkJGTVIbARlVUQkBClBWVVQFVQxSAQ4DHgBRAU0TBQUEVFACB1MCCwtVUVIGUxMbAAVdRVY/"
},
{
"key": "X-RateLimit-Limit",
"value": "20"
},
{
"key": "X-RateLimit-Remaining",
"value": "0"
},
{
"key": "X-RateLimit-Reset",
"value": "1559585547"
},
{
"key": "Retry-After",
"value": "59"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Expires",
"value": "Sun, 03 Jun 2018 18:11:27 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:11:27 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\": 2274,\n \"business_id\": 1966214,\n \"system_id\": 4236410,\n \"invoice_profile_id\": null,\n \"client_user_id\": 32040,\n \"start_date\": \"2019-06-05\",\n \"next_period_start_date\": \"2019-06-03\",\n \"fee\": \"600.00\",\n \"excess_rate\": \"200.00\",\n \"budgeted_time\": 144000,\n \"active\": true,\n \"created_at\": \"2019-06-03T18:11:26\",\n \"updated_at\": \"2019-06-03T18:11:26\"\n }\n}"
}
]
}