AutoIt
AutoIt
GetHarvest - Get Client Contacts
See more GetHarvest Examples
Returns a list of your contacts.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oHttp = ObjCreate("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 = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oHttp.QuickGetSb("https://api.harvestapp.com/v2/contacts",$oSbResponseBody)
If ($bSuccess = False) Then
ConsoleWrite($oHttp.LastErrorText & @CRLF)
Exit
EndIf
$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False
ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)
Local $iRespStatusCode = $oHttp.LastStatus
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
ConsoleWrite("Response Header:" & @CRLF)
ConsoleWrite($oHttp.LastHeader & @CRLF)
ConsoleWrite("Failed." & @CRLF)
Exit
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
Local $iPer_page
Local $iTotal_pages
Local $iTotal_entries
Local $sNext_page
Local $sPrevious_page
Local $iPage
Local $sLinksFirst
Local $sLinksNext
Local $sLinksPrevious
Local $sLinksLast
Local $i
Local $iCount_i
Local $id
Local $sTitle
Local $sFirst_name
Local $sLast_name
Local $sEmail
Local $sPhone_office
Local $sPhone_mobile
Local $sFax
Local $sCreated_at
Local $sUpdated_at
Local $iClientId
Local $sClientName
$iPer_page = $oJResp.IntOf("per_page")
$iTotal_pages = $oJResp.IntOf("total_pages")
$iTotal_entries = $oJResp.IntOf("total_entries")
$sNext_page = $oJResp.StringOf("next_page")
$sPrevious_page = $oJResp.StringOf("previous_page")
$iPage = $oJResp.IntOf("page")
$sLinksFirst = $oJResp.StringOf("links.first")
$sLinksNext = $oJResp.StringOf("links.next")
$sLinksPrevious = $oJResp.StringOf("links.previous")
$sLinksLast = $oJResp.StringOf("links.last")
$i = 0
$iCount_i = $oJResp.SizeOfArray("contacts")
While $i < $iCount_i
$oJResp.I = $i
$id = $oJResp.IntOf("contacts[i].id")
$sTitle = $oJResp.StringOf("contacts[i].title")
$sFirst_name = $oJResp.StringOf("contacts[i].first_name")
$sLast_name = $oJResp.StringOf("contacts[i].last_name")
$sEmail = $oJResp.StringOf("contacts[i].email")
$sPhone_office = $oJResp.StringOf("contacts[i].phone_office")
$sPhone_mobile = $oJResp.StringOf("contacts[i].phone_mobile")
$sFax = $oJResp.StringOf("contacts[i].fax")
$sCreated_at = $oJResp.StringOf("contacts[i].created_at")
$sUpdated_at = $oJResp.StringOf("contacts[i].updated_at")
$iClientId = $oJResp.IntOf("contacts[i].client.id")
$sClientName = $oJResp.StringOf("contacts[i].client.name")
$i = $i + 1
Wend