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
(Unicode C) GetHarvest - Test Personal Access TokenDemonstrates how to test your GetHarvest Personal Access Token
#include <C_CkHttpW.h> #include <C_CkStringBuilderW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkStringBuilderW sbResponseBody; HCkJsonObjectW jResp; int respStatusCode; int id; const wchar_t *first_name; const wchar_t *last_name; const wchar_t *email; const wchar_t *telephone; const wchar_t *timezone; int weekly_capacity; BOOL has_access_to_all_future_projects; BOOL is_contractor; BOOL is_admin; BOOL is_project_manager; BOOL can_see_rates; BOOL can_create_projects; BOOL can_create_invoices; BOOL is_active; const wchar_t *created_at; const wchar_t *updated_at; const wchar_t *default_hourly_rate; const wchar_t *cost_rate; const wchar_t *avatar_url; int i; int count_i; const wchar_t *strVal; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); CkHttpW_SetRequestHeader(http,L"User-Agent",L"Harvest API Example"); CkHttpW_SetRequestHeader(http,L"Harvest-Account-ID",L"ACCOUNT_ID"); CkHttpW_SetRequestHeader(http,L"Authorization",L"Bearer ACCESS_TOKEN"); sbResponseBody = CkStringBuilderW_Create(); success = CkHttpW_QuickGetSb(http,L"https://api.harvestapp.com/api/v2/users/me.json",sbResponseBody); if (success != TRUE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbResponseBody); return; } jResp = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(jResp,sbResponseBody); CkJsonObjectW_putEmitCompact(jResp,FALSE); wprintf(L"Response Body:\n"); wprintf(L"%s\n",CkJsonObjectW_emit(jResp)); respStatusCode = CkHttpW_getLastStatus(http); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",CkHttpW_lastResponseHeader(http)); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); return; } // 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 = CkJsonObjectW_IntOf(jResp,L"id"); first_name = CkJsonObjectW_stringOf(jResp,L"first_name"); last_name = CkJsonObjectW_stringOf(jResp,L"last_name"); email = CkJsonObjectW_stringOf(jResp,L"email"); telephone = CkJsonObjectW_stringOf(jResp,L"telephone"); timezone = CkJsonObjectW_stringOf(jResp,L"timezone"); weekly_capacity = CkJsonObjectW_IntOf(jResp,L"weekly_capacity"); has_access_to_all_future_projects = CkJsonObjectW_BoolOf(jResp,L"has_access_to_all_future_projects"); is_contractor = CkJsonObjectW_BoolOf(jResp,L"is_contractor"); is_admin = CkJsonObjectW_BoolOf(jResp,L"is_admin"); is_project_manager = CkJsonObjectW_BoolOf(jResp,L"is_project_manager"); can_see_rates = CkJsonObjectW_BoolOf(jResp,L"can_see_rates"); can_create_projects = CkJsonObjectW_BoolOf(jResp,L"can_create_projects"); can_create_invoices = CkJsonObjectW_BoolOf(jResp,L"can_create_invoices"); is_active = CkJsonObjectW_BoolOf(jResp,L"is_active"); created_at = CkJsonObjectW_stringOf(jResp,L"created_at"); updated_at = CkJsonObjectW_stringOf(jResp,L"updated_at"); default_hourly_rate = CkJsonObjectW_stringOf(jResp,L"default_hourly_rate"); cost_rate = CkJsonObjectW_stringOf(jResp,L"cost_rate"); avatar_url = CkJsonObjectW_stringOf(jResp,L"avatar_url"); i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"roles"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); strVal = CkJsonObjectW_stringOf(jResp,L"roles[i]"); i = i + 1; } CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.