Sample code for 30+ languages & platforms
Unicode C++

GetHarvest - Test Personal Access Token

See more GetHarvest Examples

Demonstrates how to test your GetHarvest Personal Access Token

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkHttpW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    bool success = false;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttpW http;

    http.SetRequestHeader(L"User-Agent",L"Harvest API Example");
    http.SetRequestHeader(L"Harvest-Account-ID",L"ACCOUNT_ID");
    http.SetRequestHeader(L"Authorization",L"Bearer ACCESS_TOKEN");

    CkStringBuilderW sbResponseBody;
    success = http.QuickGetSb(L"https://api.harvestapp.com/api/v2/users/me.json",sbResponseBody);
    if (success != true) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",jResp.emit());

    int respStatusCode = http.get_LastStatus();
    wprintf(L"Response Status Code = %d\n",respStatusCode);

    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",http.lastResponseHeader());
        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

    int id;
    const wchar_t *first_name = 0;
    const wchar_t *last_name = 0;
    const wchar_t *email = 0;
    const wchar_t *telephone = 0;
    const wchar_t *timezone = 0;
    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 = 0;
    const wchar_t *updated_at = 0;
    const wchar_t *default_hourly_rate = 0;
    const wchar_t *cost_rate = 0;
    const wchar_t *avatar_url = 0;
    int i;
    int count_i;
    const wchar_t *strVal = 0;

    id = jResp.IntOf(L"id");
    first_name = jResp.stringOf(L"first_name");
    last_name = jResp.stringOf(L"last_name");
    email = jResp.stringOf(L"email");
    telephone = jResp.stringOf(L"telephone");
    timezone = jResp.stringOf(L"timezone");
    weekly_capacity = jResp.IntOf(L"weekly_capacity");
    has_access_to_all_future_projects = jResp.BoolOf(L"has_access_to_all_future_projects");
    is_contractor = jResp.BoolOf(L"is_contractor");
    is_admin = jResp.BoolOf(L"is_admin");
    is_project_manager = jResp.BoolOf(L"is_project_manager");
    can_see_rates = jResp.BoolOf(L"can_see_rates");
    can_create_projects = jResp.BoolOf(L"can_create_projects");
    can_create_invoices = jResp.BoolOf(L"can_create_invoices");
    is_active = jResp.BoolOf(L"is_active");
    created_at = jResp.stringOf(L"created_at");
    updated_at = jResp.stringOf(L"updated_at");
    default_hourly_rate = jResp.stringOf(L"default_hourly_rate");
    cost_rate = jResp.stringOf(L"cost_rate");
    avatar_url = jResp.stringOf(L"avatar_url");
    i = 0;
    count_i = jResp.SizeOfArray(L"roles");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"roles[i]");
        i = i + 1;
    }
    }