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
(PureBasic) GetHarvest - Test Personal Access TokenDemonstrates how to test your GetHarvest Personal Access Token
IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i CkHttp::ckSetRequestHeader(http,"User-Agent","Harvest API Example") CkHttp::ckSetRequestHeader(http,"Harvest-Account-ID","ACCOUNT_ID") CkHttp::ckSetRequestHeader(http,"Authorization","Bearer ACCESS_TOKEN") sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkHttp::ckQuickGetSb(http,"https://api.harvestapp.com/api/v2/users/me.json",sbResponseBody) If success <> 1 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkStringBuilder::ckDispose(sbResponseBody) ProcedureReturn EndIf jResp.i = CkJsonObject::ckCreate() If jResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoadSb(jResp,sbResponseBody) CkJsonObject::setCkEmitCompact(jResp, 0) Debug "Response Body:" Debug CkJsonObject::ckEmit(jResp) respStatusCode.i = CkHttp::ckLastStatus(http) Debug "Response Status Code = " + Str(respStatusCode) If respStatusCode >= 400 Debug "Response Header:" Debug CkHttp::ckLastResponseHeader(http) CkHttp::ckDispose(http) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndIf ; Sample JSON response: ; { ; "id": 2826142, ; "first_name": "Joe", ; "last_name": "Johnson", ; "email": "joe@example.com", ; "telephone": "", ; "timezone": "Central Time (US & Canada)", ; "weekly_capacity": 126000, ; "has_access_to_all_future_projects": false, ; "is_contractor": false, ; "is_admin": true, ; "is_project_manager": false, ; "can_see_rates": true, ; "can_create_projects": true, ; "can_create_invoices": true, ; "is_active": true, ; "created_at": "2019-06-06T15:57:58Z", ; "updated_at": "2019-06-06T15:58:32Z", ; "default_hourly_rate": 175.0, ; "cost_rate": 60.0, ; "roles": [ ; "role1", ; "role2" ; ], ; "avatar_url": "https://d3s3969qhosaug.cloudfront.net/default-avatars/4d46.png?1559836678" ; } ; Sample code for parsing the JSON response... ; Use the following online tool to generate parsing code from sample JSON: ; Generate Parsing Code from JSON id.i first_name.s last_name.s email.s telephone.s timezone.s weekly_capacity.i has_access_to_all_future_projects.i is_contractor.i is_admin.i is_project_manager.i can_see_rates.i can_create_projects.i can_create_invoices.i is_active.i created_at.s updated_at.s default_hourly_rate.s cost_rate.s avatar_url.s i.i count_i.i strVal.s id = CkJsonObject::ckIntOf(jResp,"id") first_name = CkJsonObject::ckStringOf(jResp,"first_name") last_name = CkJsonObject::ckStringOf(jResp,"last_name") email = CkJsonObject::ckStringOf(jResp,"email") telephone = CkJsonObject::ckStringOf(jResp,"telephone") timezone = CkJsonObject::ckStringOf(jResp,"timezone") weekly_capacity = CkJsonObject::ckIntOf(jResp,"weekly_capacity") has_access_to_all_future_projects = CkJsonObject::ckBoolOf(jResp,"has_access_to_all_future_projects") is_contractor = CkJsonObject::ckBoolOf(jResp,"is_contractor") is_admin = CkJsonObject::ckBoolOf(jResp,"is_admin") is_project_manager = CkJsonObject::ckBoolOf(jResp,"is_project_manager") can_see_rates = CkJsonObject::ckBoolOf(jResp,"can_see_rates") can_create_projects = CkJsonObject::ckBoolOf(jResp,"can_create_projects") can_create_invoices = CkJsonObject::ckBoolOf(jResp,"can_create_invoices") is_active = CkJsonObject::ckBoolOf(jResp,"is_active") created_at = CkJsonObject::ckStringOf(jResp,"created_at") updated_at = CkJsonObject::ckStringOf(jResp,"updated_at") default_hourly_rate = CkJsonObject::ckStringOf(jResp,"default_hourly_rate") cost_rate = CkJsonObject::ckStringOf(jResp,"cost_rate") avatar_url = CkJsonObject::ckStringOf(jResp,"avatar_url") i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"roles") While i < count_i CkJsonObject::setCkI(jResp, i) strVal = CkJsonObject::ckStringOf(jResp,"roles[i]") i = i + 1 Wend CkHttp::ckDispose(http) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.