lianja / New FreshBooks / Undelete Retainer
Back to Collection Items
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loHttp = createobject("CkHttp")
// 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": true
// }
// }
loJson = createobject("CkJsonObject")
loJson.UpdateBool("retainer.active",.T.)
// Adds the "Authorization: Bearer <access_token>" header.
loHttp.AuthToken = "<access_token>"
loHttp.SetRequestHeader("Content-Type","application/json")
loSbRequestBody = createobject("CkStringBuilder")
loJson.EmitSb(loSbRequestBody)
loResp = loHttp.PTextSb("PUT","https://api.freshbooks.com/comments/business/{{businessId}}/retainer/{{retainerId}}",loSbRequestBody,"utf-8","application/json",.F.,.F.)
if (loHttp.LastMethodSuccess = .F.) then
? loHttp.LastErrorText
release loHttp
release loJson
release loSbRequestBody
return
endif
loSbResponseBody = createobject("CkStringBuilder")
loResp.GetBodySb(loSbResponseBody)
loJResp = createobject("CkJsonObject")
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = .F.
? "Response Body:"
? loJResp.Emit()
lnRespStatusCode = loResp.StatusCode
? "Response Status Code = " + str(lnRespStatusCode)
if (lnRespStatusCode >= 400) then
? "Response Header:"
? loResp.Header
? "Failed."
release loResp
release loHttp
release loJson
release loSbRequestBody
release loSbResponseBody
release loJResp
return
endif
release loResp
// 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": true,
// "created_at": "2019-06-03T15:42:49",
// "updated_at": "2019-06-03T18:25:02"
// }
// }
// Sample code for parsing the JSON response...
// Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
lnId = loJResp.IntOf("retainer.id")
lnBusiness_id = loJResp.IntOf("retainer.business_id")
lnSystem_id = loJResp.IntOf("retainer.system_id")
lcInvoice_profile_id = loJResp.StringOf("retainer.invoice_profile_id")
lnClient_user_id = loJResp.IntOf("retainer.client_user_id")
lcStart_date = loJResp.StringOf("retainer.start_date")
lcNext_period_start_date = loJResp.StringOf("retainer.next_period_start_date")
lcFee = loJResp.StringOf("retainer.fee")
lcExcess_rate = loJResp.StringOf("retainer.excess_rate")
lnBudgeted_time = loJResp.IntOf("retainer.budgeted_time")
llActive = loJResp.BoolOf("retainer.active")
lcCreated_at = loJResp.StringOf("retainer.created_at")
lcUpdated_at = loJResp.StringOf("retainer.updated_at")
release loHttp
release loJson
release loSbRequestBody
release loSbResponseBody
release loJResp
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
-H "Content-Type: application/json"
-d '{
"retainer": {
"active": true
}
}'
https://api.freshbooks.com/comments/business/{{businessId}}/retainer/{{retainerId}}
Postman Collection Item JSON
{
"name": "Undelete Retainer",
"request": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"retainer\": {\n \"active\": true\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": "Undelete Retainer Success",
"originalRequest": {
"method": "PUT",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"retainer\": {\n \"active\": true\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": "PxQBWV5TCBABVllUBAQOU10TGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4FDFZFVRYSBxlDUhULRERQBxVNEFUWWQtWXUYcQQBKDkQTUAdeRFIVBwpWVkJGTVIbARlXVAUHAFNfUFUAUA5bDw8BBh9QCU0TUgpbBQQEBABVDwRRVwBaBRMbAAVdRVY/"
},
{
"key": "X-RateLimit-Limit",
"value": "20"
},
{
"key": "X-RateLimit-Remaining",
"value": "0"
},
{
"key": "X-RateLimit-Reset",
"value": "1559586355"
},
{
"key": "Retry-After",
"value": "52"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Expires",
"value": "Sun, 03 Jun 2018 18:25:02 GMT"
},
{
"key": "Cache-Control",
"value": "no-cache"
},
{
"key": "Via",
"value": "1.1 google"
},
{
"key": "Via",
"value": "1.1 varnish"
},
{
"key": "Content-Length",
"value": "349"
},
{
"key": "Accept-Ranges",
"value": "bytes"
},
{
"key": "Date",
"value": "Mon, 03 Jun 2019 18:25:02 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\": true,\n \"created_at\": \"2019-06-03T15:42:49\",\n \"updated_at\": \"2019-06-03T18:25:02\"\n }\n}"
}
]
}