AutoIt
AutoIt
GetHarvest - List Clients
See more GetHarvest Examples
Returns a list of your clients.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/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 = ObjCreate("Chilkat.StringBuilder")
$bSuccess = $oHttp.QuickGetSb("https://api.harvestapp.com/v2/clients",$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:
; {
; "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
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 $sName
Local $bIs_active
Local $sAddress
Local $sCreated_at
Local $sUpdated_at
Local $sCurrency
$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("clients")
While $i < $iCount_i
$oJResp.I = $i
$id = $oJResp.IntOf("clients[i].id")
$sName = $oJResp.StringOf("clients[i].name")
$bIs_active = $oJResp.BoolOf("clients[i].is_active")
$sAddress = $oJResp.StringOf("clients[i].address")
$sCreated_at = $oJResp.StringOf("clients[i].created_at")
$sUpdated_at = $oJResp.StringOf("clients[i].updated_at")
$sCurrency = $oJResp.StringOf("clients[i].currency")
$i = $i + 1
Wend