Back to Collection Items
IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkHttpResponse.pb"
Procedure ChilkatExample()
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i
; Use this online tool to generate code from sample JSON: Generate Code to Create JSON
; The following JSON is sent in the request body.
; {
; "bill_vendor": {
; "vis_state": 1
; }
; }
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateInt(json,"bill_vendor.vis_state",1)
; Adds the "Authorization: Bearer <access_token>" header.
CkHttp::setCkAuthToken(http, "<access_token>")
sbRequestBody.i = CkStringBuilder::ckCreate()
If sbRequestBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckEmitSb(json,sbRequestBody)
resp.i = CkHttp::ckPTextSb(http,"PUT","https://api.freshbooks.com/accounting/account/{{accountId}}/bill_vendors/bill_vendors/{{vendorId}}",sbRequestBody,"utf-8","application/json",0,0)
If CkHttp::ckLastMethodSuccess(http) = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
ProcedureReturn
EndIf
sbResponseBody.i = CkStringBuilder::ckCreate()
If sbResponseBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkHttpResponse::ckGetBodySb(resp,sbResponseBody)
jResp.i = CkJsonObject::ckCreate()
If jResp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoadSb(jResp,sbResponseBody)
CkJsonObject::setCkEmitCompact(jResp, 0)
Debug "Response Body:"
Debug CkJsonObject::ckEmit(jResp)
respStatusCode.i = CkHttpResponse::ckStatusCode(resp)
Debug "Response Status Code = " + Str(respStatusCode)
If respStatusCode >= 400
Debug "Response Header:"
Debug CkHttpResponse::ckHeader(resp)
Debug "Failed."
CkHttpResponse::ckDispose(resp)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndIf
CkHttpResponse::ckDispose(resp)
; Sample JSON response:
; (Sample code for parsing the JSON response is shown below)
; {
; "response": {
; "result": {
; "bill_vendor": {
; "account_number": "23479",
; "city": "Palo Alto",
; "country": "United States",
; "created_at": "2020-10-09 15:50:10",
; "currency_code": "USD",
; "is_1099": false,
; "language": "en",
; "outstanding_balance": [
; ],
; "overdue_balance": [
; ],
; "phone": "4158331869",
; "postal_code": null,
; "primary_contact_email": "dmiller@apple.com",
; "primary_contact_first_name": "Dorothy",
; "primary_contact_last_name": "Miller",
; "province": "California",
; "street": "1 Infinite Loop",
; "street2": null,
; "tax_defaults": [
; ],
; "updated_at": "2020-10-09 15:52:30",
; "vendor_name": "Apple",
; "vendorid": 7,
; "vis_state": 1,
; "website": "apple.com"
; }
; }
; }
; }
; Sample code for parsing the JSON response...
; Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
Account_number.s = CkJsonObject::ckStringOf(jResp,"response.result.bill_vendor.account_number")
City.s = CkJsonObject::ckStringOf(jResp,"response.result.bill_vendor.city")
Country.s = CkJsonObject::ckStringOf(jResp,"response.result.bill_vendor.country")
Created_at.s = CkJsonObject::ckStringOf(jResp,"response.result.bill_vendor.created_at")
Currency_code.s = CkJsonObject::ckStringOf(jResp,"response.result.bill_vendor.currency_code")
Is_1099.i = CkJsonObject::ckBoolOf(jResp,"response.result.bill_vendor.is_1099")
Language.s = CkJsonObject::ckStringOf(jResp,"response.result.bill_vendor.language")
Phone.s = CkJsonObject::ckStringOf(jResp,"response.result.bill_vendor.phone")
Postal_code.s = CkJsonObject::ckStringOf(jResp,"response.result.bill_vendor.postal_code")
Primary_contact_email.s = CkJsonObject::ckStringOf(jResp,"response.result.bill_vendor.primary_contact_email")
Primary_contact_first_name.s = CkJsonObject::ckStringOf(jResp,"response.result.bill_vendor.primary_contact_first_name")
Primary_contact_last_name.s = CkJsonObject::ckStringOf(jResp,"response.result.bill_vendor.primary_contact_last_name")
Province.s = CkJsonObject::ckStringOf(jResp,"response.result.bill_vendor.province")
Street.s = CkJsonObject::ckStringOf(jResp,"response.result.bill_vendor.street")
Street2.s = CkJsonObject::ckStringOf(jResp,"response.result.bill_vendor.street2")
Updated_at.s = CkJsonObject::ckStringOf(jResp,"response.result.bill_vendor.updated_at")
Vendor_name.s = CkJsonObject::ckStringOf(jResp,"response.result.bill_vendor.vendor_name")
Vendorid.i = CkJsonObject::ckIntOf(jResp,"response.result.bill_vendor.vendorid")
Vis_state.i = CkJsonObject::ckIntOf(jResp,"response.result.bill_vendor.vis_state")
Website.s = CkJsonObject::ckStringOf(jResp,"response.result.bill_vendor.website")
i.i = 0
count_i.i = CkJsonObject::ckSizeOfArray(jResp,"response.result.bill_vendor.outstanding_balance")
While i < count_i
CkJsonObject::setCkI(jResp, i)
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"response.result.bill_vendor.overdue_balance")
While i < count_i
CkJsonObject::setCkI(jResp, i)
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"response.result.bill_vendor.tax_defaults")
While i < count_i
CkJsonObject::setCkI(jResp, i)
i = i + 1
Wend
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndProcedure
Curl Command
curl -X PUT
-H "Authorization: Bearer <access_token>"
-d '{
"bill_vendor": {
"vis_state": 1
}
}'
https://api.freshbooks.com/accounting/account/{{accountId}}/bill_vendors/bill_vendors/{{vendorId}}
Postman Collection Item JSON
{
"name": "Delete Vendor",
"request": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"bill_vendor\": {\n \"vis_state\": 1\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/bill_vendors/bill_vendors/{{vendorId}}",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"bill_vendors",
"bill_vendors",
"{{vendorId}}"
]
}
},
"response": [
{
"name": "Delete Vendor",
"originalRequest": {
"method": "PUT",
"header": [
],
"body": {
"mode": "raw",
"raw": "{\n \"bill_vendor\": {\n \"vis_state\": 1\n }\n}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "https://api.freshbooks.com/accounting/account/{{accountId}}/bill_vendors/bill_vendors/{{vendorId}}",
"protocol": "https",
"host": [
"api",
"freshbooks",
"com"
],
"path": [
"accounting",
"account",
"{{accountId}}",
"bill_vendors",
"bill_vendors",
"{{vendorId}}"
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Server",
"value": "nginx"
},
{
"key": "Date",
"value": "Fri, 09 Oct 2020 15:52:29 GMT"
},
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Vary",
"value": "Accept-Encoding"
},
{
"key": "X-NewRelic-App-Data",
"value": "PxQBWV5TCBABVlVSAwEOVlcTGhE1AwE2QgNWEVlbQFtcCxYnRA9QFg1ZWU4DFVdfRgFPCkNFR0gGWFpfPRAGDFQNShECWl1eXxNcD1UOQUBIBhtRSFUJBQFWUlMOCANQVgkPA1RKVlEcQAFWWQhVAwIAW1hSUgJRUg8VTQACVEBVOQ=="
},
{
"key": "X-Frame-Options",
"value": "SAMEORIGIN"
},
{
"key": "X-XSS-Protection",
"value": "1; mode=block"
},
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "Content-Security-Policy",
"value": "default-src 'self'"
},
{
"key": "X-Content-Security-Policy",
"value": "default-src 'self'"
},
{
"key": "Strict-Transport-Security",
"value": "max-age=31556926; includeSubDomains; preload"
},
{
"key": "Referrer-Policy",
"value": "strict-origin-when-cross-origin"
},
{
"key": "X-RateLimit-Limit",
"value": "600"
},
{
"key": "X-RateLimit-Remaining",
"value": "599"
},
{
"key": "X-RateLimit-Reset",
"value": "1602258810"
},
{
"key": "Retry-After",
"value": "60"
},
{
"key": "Access-Control-Allow-Origin",
"value": "*"
},
{
"key": "Content-Encoding",
"value": "gzip"
},
{
"key": "Via",
"value": "1.1 google"
},
{
"key": "Alt-Svc",
"value": "h3-Q050=\":443\"; ma=2592000,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,quic=\":443\"; ma=2592000; v=\"46,43\""
},
{
"key": "Transfer-Encoding",
"value": "chunked"
}
],
"cookie": [
],
"body": "{\n \"response\": {\n \"result\": {\n \"bill_vendor\": {\n \"account_number\": \"23479\",\n \"city\": \"Palo Alto\",\n \"country\": \"United States\",\n \"created_at\": \"2020-10-09 15:50:10\",\n \"currency_code\": \"USD\",\n \"is_1099\": false,\n \"language\": \"en\",\n \"outstanding_balance\": [],\n \"overdue_balance\": [],\n \"phone\": \"4158331869\",\n \"postal_code\": null,\n \"primary_contact_email\": \"dmiller@apple.com\",\n \"primary_contact_first_name\": \"Dorothy\",\n \"primary_contact_last_name\": \"Miller\",\n \"province\": \"California\",\n \"street\": \"1 Infinite Loop\",\n \"street2\": null,\n \"tax_defaults\": [],\n \"updated_at\": \"2020-10-09 15:52:30\",\n \"vendor_name\": \"Apple\",\n \"vendorid\": 7,\n \"vis_state\": 1,\n \"website\": \"apple.com\"\n }\n }\n }\n}"
}
]
}