Lianja
Lianja
GetHarvest - List Clients
See more GetHarvest Examples
Returns a list of your clients.Chilkat Lianja Downloads
llSuccess = .F.
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loHttp = createobject("CkHttp")
// Implements the following CURL command:
// curl "https://api.harvestapp.com/v2/clients" \
// -H "Authorization: Bearer ACCESS_TOKEN" \
// -H "Harvest-Account-Id: ACCOUNT_ID" \
// -H "User-Agent: MyApp (yourname@example.com)"
loHttp.SetRequestHeader("User-Agent","MyApp (yourname@example.com)")
loHttp.SetRequestHeader("Authorization","Bearer ACCESS_TOKEN")
loHttp.SetRequestHeader("Harvest-Account-Id","ACCOUNT_ID")
loSbResponseBody = createobject("CkStringBuilder")
llSuccess = loHttp.QuickGetSb("https://api.harvestapp.com/v2/clients",loSbResponseBody)
if (llSuccess = .F.) then
? loHttp.LastErrorText
release loHttp
release loSbResponseBody
return
endif
loJResp = createobject("CkJsonObject")
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = .F.
? "Response Body:"
? loJResp.Emit()
lnRespStatusCode = loHttp.LastStatus
? "Response Status Code = " + str(lnRespStatusCode)
if (lnRespStatusCode >= 400) then
? "Response Header:"
? loHttp.LastHeader
? "Failed."
release loHttp
release loSbResponseBody
release loJResp
return
endif
// Sample JSON response:
// {
// "clients": [
// {
// "id": 5735776,
// "name": "123 Industries",
// "is_active": true,
// "address": "123 Main St.\r\nAnytown, LA 71223",
// "created_at": "2017-06-26T21:02:12Z",
// "updated_at": "2017-06-26T21:34:11Z",
// "currency": "EUR"
// },
// {
// "id": 5735774,
// "name": "ABC Corp",
// "is_active": true,
// "address": "456 Main St.\r\nAnytown, CT 06467",
// "created_at": "2017-06-26T21:01:52Z",
// "updated_at": "2017-06-26T21:27:07Z",
// "currency": "USD"
// }
// ],
// "per_page": 100,
// "total_pages": 1,
// "total_entries": 2,
// "next_page": null,
// "previous_page": null,
// "page": 1,
// "links": {
// "first": "https://api.harvestapp.com/v2/clients?page=1&per_page=100",
// "next": null,
// "previous": null,
// "last": "https://api.harvestapp.com/v2/clients?page=1&per_page=100"
// }
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
lnPer_page = loJResp.IntOf("per_page")
lnTotal_pages = loJResp.IntOf("total_pages")
lnTotal_entries = loJResp.IntOf("total_entries")
lcNext_page = loJResp.StringOf("next_page")
lcPrevious_page = loJResp.StringOf("previous_page")
lnPage = loJResp.IntOf("page")
lcLinksFirst = loJResp.StringOf("links.first")
lcLinksNext = loJResp.StringOf("links.next")
lcLinksPrevious = loJResp.StringOf("links.previous")
lcLinksLast = loJResp.StringOf("links.last")
i = 0
lnCount_i = loJResp.SizeOfArray("clients")
do while i < lnCount_i
loJResp.I = i
lnId = loJResp.IntOf("clients[i].id")
lcName = loJResp.StringOf("clients[i].name")
llIs_active = loJResp.BoolOf("clients[i].is_active")
lcAddress = loJResp.StringOf("clients[i].address")
lcCreated_at = loJResp.StringOf("clients[i].created_at")
lcUpdated_at = loJResp.StringOf("clients[i].updated_at")
lcCurrency = loJResp.StringOf("clients[i].currency")
i = i + 1
enddo
release loHttp
release loSbResponseBody
release loJResp