PureBasic / easybill REST API / Fetch customer contact list
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
queryParams.i = CkJsonObject::ckCreate()
If queryParams.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateString(queryParams,"limit","<integer>")
CkJsonObject::ckUpdateString(queryParams,"page","<integer>")
CkHttp::ckSetRequestHeader(http,"Authorization","{{apiKey}}")
CkHttp::ckSetRequestHeader(http,"Accept","application/json")
resp.i = CkHttp::ckQuickRequestParams(http,"GET","https://api.easybill.de/rest/v1/customers/:customerId/contacts",queryParams)
If CkHttp::ckLastMethodSuccess(http) = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(queryParams)
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(queryParams)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndIf
CkHttpResponse::ckDispose(resp)
; Sample JSON response:
; (Sample code for parsing the JSON response is shown below)
; {
; "page": "<integer>",
; "pages": "<integer>",
; "limit": "<integer>",
; "total": "<integer>",
; "items": [
; {
; "city": "<string>",
; "street": "<string>",
; "state": "<string>",
; "company_name": "<string>",
; "country": "<string>",
; "department": null,
; "fax": null,
; "first_name": null,
; "id": "<long>",
; "last_name": null,
; "login_id": "<long>",
; "mobile": null,
; "note": null,
; "personal": false,
; "phone_1": null,
; "phone_2": null,
; "salutation": "<integer>",
; "suffix_1": null,
; "suffix_2": null,
; "title": null,
; "zip_code": null,
; "created_at": "<string>",
; "updated_at": "<string>"
; },
; {
; "city": "<string>",
; "street": "<string>",
; "state": "<string>",
; "company_name": "<string>",
; "country": "<string>",
; "department": null,
; "fax": null,
; "first_name": null,
; "id": "<long>",
; "last_name": null,
; "login_id": "<long>",
; "mobile": null,
; "note": null,
; "personal": false,
; "phone_1": null,
; "phone_2": null,
; "salutation": "<integer>",
; "suffix_1": null,
; "suffix_2": null,
; "title": null,
; "zip_code": null,
; "created_at": "<string>",
; "updated_at": "<string>"
; }
; ]
; }
; Sample code for parsing the JSON response...
; Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code
city.s
street.s
state.s
company_name.s
country.s
department.s
fax.s
first_name.s
id.s
last_name.s
login_id.s
mobile.s
note.s
personal.i
phone_1.s
phone_2.s
salutation.s
suffix_1.s
suffix_2.s
title.s
zip_code.s
created_at.s
updated_at.s
page.s = CkJsonObject::ckStringOf(jResp,"page")
pages.s = CkJsonObject::ckStringOf(jResp,"pages")
limit.s = CkJsonObject::ckStringOf(jResp,"limit")
total.s = CkJsonObject::ckStringOf(jResp,"total")
i.i = 0
count_i.i = CkJsonObject::ckSizeOfArray(jResp,"items")
While i < count_i
CkJsonObject::setCkI(jResp, i)
city = CkJsonObject::ckStringOf(jResp,"items[i].city")
street = CkJsonObject::ckStringOf(jResp,"items[i].street")
state = CkJsonObject::ckStringOf(jResp,"items[i].state")
company_name = CkJsonObject::ckStringOf(jResp,"items[i].company_name")
country = CkJsonObject::ckStringOf(jResp,"items[i].country")
department = CkJsonObject::ckStringOf(jResp,"items[i].department")
fax = CkJsonObject::ckStringOf(jResp,"items[i].fax")
first_name = CkJsonObject::ckStringOf(jResp,"items[i].first_name")
id = CkJsonObject::ckStringOf(jResp,"items[i].id")
last_name = CkJsonObject::ckStringOf(jResp,"items[i].last_name")
login_id = CkJsonObject::ckStringOf(jResp,"items[i].login_id")
mobile = CkJsonObject::ckStringOf(jResp,"items[i].mobile")
note = CkJsonObject::ckStringOf(jResp,"items[i].note")
personal = CkJsonObject::ckBoolOf(jResp,"items[i].personal")
phone_1 = CkJsonObject::ckStringOf(jResp,"items[i].phone_1")
phone_2 = CkJsonObject::ckStringOf(jResp,"items[i].phone_2")
salutation = CkJsonObject::ckStringOf(jResp,"items[i].salutation")
suffix_1 = CkJsonObject::ckStringOf(jResp,"items[i].suffix_1")
suffix_2 = CkJsonObject::ckStringOf(jResp,"items[i].suffix_2")
title = CkJsonObject::ckStringOf(jResp,"items[i].title")
zip_code = CkJsonObject::ckStringOf(jResp,"items[i].zip_code")
created_at = CkJsonObject::ckStringOf(jResp,"items[i].created_at")
updated_at = CkJsonObject::ckStringOf(jResp,"items[i].updated_at")
i = i + 1
Wend
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(queryParams)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndProcedure
Curl Command
curl -G -d "limit=%3Cinteger%3E"
-d "page=%3Cinteger%3E"
-H "Authorization: {{apiKey}}"
-H "Accept: application/json"
https://api.easybill.de/rest/v1/customers/:customerId/contacts
Postman Collection Item JSON
{
"name": "Fetch customer contact list",
"request": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
}
],
"url": {
"raw": "{{baseUrl}}/customers/:customerId/contacts?limit=<integer>&page=<integer>",
"host": [
"{{baseUrl}}"
],
"path": [
"customers",
":customerId",
"contacts"
],
"query": [
{
"key": "limit",
"value": "<integer>",
"description": "Limited the result. Default is 100. Maximum can be 1000."
},
{
"key": "page",
"value": "<integer>",
"description": "Set current Page. Default is 1."
}
],
"variable": [
{
"key": "customerId",
"value": "<long>",
"description": "(Required) ID of customer that needs to be fetched"
}
]
}
},
"response": [
{
"name": "Successful operation",
"originalRequest": {
"method": "GET",
"header": [
{
"key": "Accept",
"value": "application/json"
},
{
"description": "Added as a part of security scheme: apikey",
"key": "Authorization",
"value": "<API Key>"
}
],
"url": {
"raw": "{{baseUrl}}/customers/:customerId/contacts?limit=<integer>&page=<integer>",
"host": [
"{{baseUrl}}"
],
"path": [
"customers",
":customerId",
"contacts"
],
"query": [
{
"key": "limit",
"value": "<integer>",
"description": "Limited the result. Default is 100. Maximum can be 1000."
},
{
"key": "page",
"value": "<integer>",
"description": "Set current Page. Default is 1."
}
],
"variable": [
{
"key": "customerId"
}
]
}
},
"status": "OK",
"code": 200,
"_postman_previewlanguage": "json",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"cookie": [
],
"body": "{\n \"page\": \"<integer>\",\n \"pages\": \"<integer>\",\n \"limit\": \"<integer>\",\n \"total\": \"<integer>\",\n \"items\": [\n {\n \"city\": \"<string>\",\n \"street\": \"<string>\",\n \"state\": \"<string>\",\n \"company_name\": \"<string>\",\n \"country\": \"<string>\",\n \"department\": null,\n \"fax\": null,\n \"first_name\": null,\n \"id\": \"<long>\",\n \"last_name\": null,\n \"login_id\": \"<long>\",\n \"mobile\": null,\n \"note\": null,\n \"personal\": false,\n \"phone_1\": null,\n \"phone_2\": null,\n \"salutation\": \"<integer>\",\n \"suffix_1\": null,\n \"suffix_2\": null,\n \"title\": null,\n \"zip_code\": null,\n \"created_at\": \"<string>\",\n \"updated_at\": \"<string>\"\n },\n {\n \"city\": \"<string>\",\n \"street\": \"<string>\",\n \"state\": \"<string>\",\n \"company_name\": \"<string>\",\n \"country\": \"<string>\",\n \"department\": null,\n \"fax\": null,\n \"first_name\": null,\n \"id\": \"<long>\",\n \"last_name\": null,\n \"login_id\": \"<long>\",\n \"mobile\": null,\n \"note\": null,\n \"personal\": false,\n \"phone_1\": null,\n \"phone_2\": null,\n \"salutation\": \"<integer>\",\n \"suffix_1\": null,\n \"suffix_2\": null,\n \"title\": null,\n \"zip_code\": null,\n \"created_at\": \"<string>\",\n \"updated_at\": \"<string>\"\n }\n ]\n}"
},
{
"name": "Too Many Requests",
"originalRequest": {
"method": "GET",
"header": [
{
"description": "Added as a part of security scheme: apikey",
"key": "Authorization",
"value": "<API Key>"
}
],
"url": {
"raw": "{{baseUrl}}/customers/:customerId/contacts?limit=<integer>&page=<integer>",
"host": [
"{{baseUrl}}"
],
"path": [
"customers",
":customerId",
"contacts"
],
"query": [
{
"key": "limit",
"value": "<integer>",
"description": "Limited the result. Default is 100. Maximum can be 1000."
},
{
"key": "page",
"value": "<integer>",
"description": "Set current Page. Default is 1."
}
],
"variable": [
{
"key": "customerId"
}
]
}
},
"status": "Too Many Requests",
"code": 429,
"_postman_previewlanguage": "text",
"header": [
],
"cookie": [
],
"body": ""
}
]
}