Xbase++
Xbase++
GetHarvest - Get Client Contacts
See more GetHarvest Examples
Returns a list of your contacts.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 cTitle
LOCAL cFirst_name
LOCAL cLast_name
LOCAL cEmail
LOCAL cPhone_office
LOCAL cPhone_mobile
LOCAL cFax
LOCAL cCreated_at
LOCAL cUpdated_at
LOCAL nClientId
LOCAL cClientName
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/contacts" \
// -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/contacts", 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:
// {
// "contacts": [
// {
// "id": 4706479,
// "title": "Owner",
// "first_name": "Jane",
// "last_name": "Doe",
// "email": "janedoe@example.com",
// "phone_office": "(203) 697-8885",
// "phone_mobile": "(203) 697-8886",
// "fax": "(203) 697-8887",
// "created_at": "2017-06-26T21:20:07Z",
// "updated_at": "2017-06-26T21:27:07Z",
// "client": {
// "id": 5735774,
// "name": "ABC Corp"
// }
// },
// {
// "id": 4706453,
// "title": "Manager",
// "first_name": "Richard",
// "last_name": "Roe",
// "email": "richardroe@example.com",
// "phone_office": "(318) 515-5905",
// "phone_mobile": "(318) 515-5906",
// "fax": "(318) 515-5907",
// "created_at": "2017-06-26T21:06:55Z",
// "updated_at": "2017-06-26T21:27:20Z",
// "client": {
// "id": 5735776,
// "name": "123 Industries"
// }
// }
// ],
// "per_page": 100,
// "total_pages": 1,
// "total_entries": 2,
// "next_page": null,
// "previous_page": null,
// "page": 1,
// "links": {
// "first": "https://api.harvestapp.com/v2/contacts?page=1&per_page=100",
// "next": null,
// "previous": null,
// "last": "https://api.harvestapp.com/v2/contacts?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("contacts")
DO WHILE i < nCount_i
oJResp:I := i
nId := oJResp:IntOf("contacts[i].id")
cTitle := oJResp:StringOf("contacts[i].title")
cFirst_name := oJResp:StringOf("contacts[i].first_name")
cLast_name := oJResp:StringOf("contacts[i].last_name")
cEmail := oJResp:StringOf("contacts[i].email")
cPhone_office := oJResp:StringOf("contacts[i].phone_office")
cPhone_mobile := oJResp:StringOf("contacts[i].phone_mobile")
cFax := oJResp:StringOf("contacts[i].fax")
cCreated_at := oJResp:StringOf("contacts[i].created_at")
cUpdated_at := oJResp:StringOf("contacts[i].updated_at")
nClientId := oJResp:IntOf("contacts[i].client.id")
cClientName := oJResp:StringOf("contacts[i].client.name")
i := i + 1
ENDDO
oHttp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()