Xbase++
Xbase++
GetHarvest - List Clients
See more GetHarvest Examples
Returns a list of your clients.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL nPer_page
LOCAL nTotal_pages
LOCAL nTotal_entries
LOCAL cNext_page
LOCAL cPrevious_page
LOCAL nPage
LOCAL cLinksFirst
LOCAL cLinksNext
LOCAL cLinksPrevious
LOCAL cLinksLast
LOCAL i
LOCAL nCount_i
LOCAL nId
LOCAL cName
LOCAL nIs_active
LOCAL cAddress
LOCAL cCreated_at
LOCAL cUpdated_at
LOCAL cCurrency
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
// 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)"
oHttp:SetRequestHeader("User-Agent", "MyApp (yourname@example.com)")
oHttp:SetRequestHeader("Authorization", "Bearer ACCESS_TOKEN")
oHttp:SetRequestHeader("Harvest-Account-Id", "ACCOUNT_ID")
oSbResponseBody := CreateObject("Chilkat.StringBuilder")
nSuccess := oHttp:QuickGetSb("https://api.harvestapp.com/v2/clients", oSbResponseBody)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oSbResponseBody:destroy()
RETURN
ENDIF
oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0
? "Response Body:"
? oJResp:Emit()
nRespStatusCode := oHttp:LastStatus
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
? "Response Header:"
? oHttp:LastHeader
? "Failed."
oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()
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
nPer_page := oJResp:IntOf("per_page")
nTotal_pages := oJResp:IntOf("total_pages")
nTotal_entries := oJResp:IntOf("total_entries")
cNext_page := oJResp:StringOf("next_page")
cPrevious_page := oJResp:StringOf("previous_page")
nPage := oJResp:IntOf("page")
cLinksFirst := oJResp:StringOf("links.first")
cLinksNext := oJResp:StringOf("links.next")
cLinksPrevious := oJResp:StringOf("links.previous")
cLinksLast := oJResp:StringOf("links.last")
i := 0
nCount_i := oJResp:SizeOfArray("clients")
DO WHILE i < nCount_i
oJResp:I := i
nId := oJResp:IntOf("clients[i].id")
cName := oJResp:StringOf("clients[i].name")
nIs_active := oJResp:BoolOf("clients[i].is_active")
cAddress := oJResp:StringOf("clients[i].address")
cCreated_at := oJResp:StringOf("clients[i].created_at")
cUpdated_at := oJResp:StringOf("clients[i].updated_at")
cCurrency := oJResp:StringOf("clients[i].currency")
i := i + 1
ENDDO
oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()