Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(AutoIt) GetHarvest - List ClientsReturns a list of your clients. For more information, see https://help.getharvest.com/api-v2/clients-api/clients/clients/
; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. $oHttp = ObjCreate("Chilkat.Http") Local $bSuccess ; 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 |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.