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
(Tcl) GetHarvest - Test Personal Access TokenDemonstrates how to test your GetHarvest Personal Access Token
load ./chilkat.dll # This example assumes the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. set http [new_CkHttp] CkHttp_SetRequestHeader $http "User-Agent" "Harvest API Example" CkHttp_SetRequestHeader $http "Harvest-Account-ID" "ACCOUNT_ID" CkHttp_SetRequestHeader $http "Authorization" "Bearer ACCESS_TOKEN" set sbResponseBody [new_CkStringBuilder] set success [CkHttp_QuickGetSb $http "https://api.harvestapp.com/api/v2/users/me.json" $sbResponseBody] if {$success != 1} then { puts [CkHttp_lastErrorText $http] delete_CkHttp $http delete_CkStringBuilder $sbResponseBody exit } set jResp [new_CkJsonObject] CkJsonObject_LoadSb $jResp $sbResponseBody CkJsonObject_put_EmitCompact $jResp 0 puts "Response Body:" puts [CkJsonObject_emit $jResp] set respStatusCode [CkHttp_get_LastStatus $http] puts "Response Status Code = $respStatusCode" if {$respStatusCode >= 400} then { puts "Response Header:" puts [CkHttp_lastResponseHeader $http] delete_CkHttp $http delete_CkStringBuilder $sbResponseBody delete_CkJsonObject $jResp exit } # 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 set id [CkJsonObject_IntOf $jResp "id"] set first_name [CkJsonObject_stringOf $jResp "first_name"] set last_name [CkJsonObject_stringOf $jResp "last_name"] set email [CkJsonObject_stringOf $jResp "email"] set telephone [CkJsonObject_stringOf $jResp "telephone"] set timezone [CkJsonObject_stringOf $jResp "timezone"] set weekly_capacity [CkJsonObject_IntOf $jResp "weekly_capacity"] set has_access_to_all_future_projects [CkJsonObject_BoolOf $jResp "has_access_to_all_future_projects"] set is_contractor [CkJsonObject_BoolOf $jResp "is_contractor"] set is_admin [CkJsonObject_BoolOf $jResp "is_admin"] set is_project_manager [CkJsonObject_BoolOf $jResp "is_project_manager"] set can_see_rates [CkJsonObject_BoolOf $jResp "can_see_rates"] set can_create_projects [CkJsonObject_BoolOf $jResp "can_create_projects"] set can_create_invoices [CkJsonObject_BoolOf $jResp "can_create_invoices"] set is_active [CkJsonObject_BoolOf $jResp "is_active"] set created_at [CkJsonObject_stringOf $jResp "created_at"] set updated_at [CkJsonObject_stringOf $jResp "updated_at"] set default_hourly_rate [CkJsonObject_stringOf $jResp "default_hourly_rate"] set cost_rate [CkJsonObject_stringOf $jResp "cost_rate"] set avatar_url [CkJsonObject_stringOf $jResp "avatar_url"] set i 0 set count_i [CkJsonObject_SizeOfArray $jResp "roles"] while {$i < $count_i} { CkJsonObject_put_I $jResp $i set strVal [CkJsonObject_stringOf $jResp "roles[i]"] set i [expr $i + 1] } delete_CkHttp $http delete_CkStringBuilder $sbResponseBody delete_CkJsonObject $jResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.