Unicode C
Unicode C
GetHarvest - Get Client Contacts
See more GetHarvest Examples
Returns a list of your contacts.Chilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkStringBuilderW sbResponseBody;
HCkJsonObjectW jResp;
int respStatusCode;
int per_page;
int total_pages;
int total_entries;
const wchar_t *next_page;
const wchar_t *previous_page;
int page;
const wchar_t *linksFirst;
const wchar_t *linksNext;
const wchar_t *linksPrevious;
const wchar_t *linksLast;
int i;
int count_i;
int id;
const wchar_t *title;
const wchar_t *first_name;
const wchar_t *last_name;
const wchar_t *email;
const wchar_t *phone_office;
const wchar_t *phone_mobile;
const wchar_t *fax;
const wchar_t *created_at;
const wchar_t *updated_at;
int clientId;
const wchar_t *clientName;
success = FALSE;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http = CkHttpW_Create();
// Implements the following CURL command:
// curl "https://api.harvestapp.com/v2/contacts" \
// -H "Authorization: Bearer ACCESS_TOKEN" \
// -H "Harvest-Account-Id: ACCOUNT_ID" \
// -H "User-Agent: MyApp (yourname@example.com)"
CkHttpW_SetRequestHeader(http,L"User-Agent",L"MyApp (yourname@example.com)");
CkHttpW_SetRequestHeader(http,L"Authorization",L"Bearer ACCESS_TOKEN");
CkHttpW_SetRequestHeader(http,L"Harvest-Account-Id",L"ACCOUNT_ID");
sbResponseBody = CkStringBuilderW_Create();
success = CkHttpW_QuickGetSb(http,L"https://api.harvestapp.com/v2/contacts",sbResponseBody);
if (success == FALSE) {
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_lastHeader(http));
wprintf(L"Failed.\n");
CkHttpW_Dispose(http);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
return;
}
// Sample JSON response:
// {
// "contacts": [
// {
// "id": 4706479,
// "title": "Owner",
// "first_name": "Jane",
// "last_name": "Doe",
// "email": "janedoe@example.com",
// "phone_office": "(203) 697-8885",
// "phone_mobile": "(203) 697-8886",
// "fax": "(203) 697-8887",
// "created_at": "2017-06-26T21:20:07Z",
// "updated_at": "2017-06-26T21:27:07Z",
// "client": {
// "id": 5735774,
// "name": "ABC Corp"
// }
// },
// {
// "id": 4706453,
// "title": "Manager",
// "first_name": "Richard",
// "last_name": "Roe",
// "email": "richardroe@example.com",
// "phone_office": "(318) 515-5905",
// "phone_mobile": "(318) 515-5906",
// "fax": "(318) 515-5907",
// "created_at": "2017-06-26T21:06:55Z",
// "updated_at": "2017-06-26T21:27:20Z",
// "client": {
// "id": 5735776,
// "name": "123 Industries"
// }
// }
// ],
// "per_page": 100,
// "total_pages": 1,
// "total_entries": 2,
// "next_page": null,
// "previous_page": null,
// "page": 1,
// "links": {
// "first": "https://api.harvestapp.com/v2/contacts?page=1&per_page=100",
// "next": null,
// "previous": null,
// "last": "https://api.harvestapp.com/v2/contacts?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
per_page = CkJsonObjectW_IntOf(jResp,L"per_page");
total_pages = CkJsonObjectW_IntOf(jResp,L"total_pages");
total_entries = CkJsonObjectW_IntOf(jResp,L"total_entries");
next_page = CkJsonObjectW_stringOf(jResp,L"next_page");
previous_page = CkJsonObjectW_stringOf(jResp,L"previous_page");
page = CkJsonObjectW_IntOf(jResp,L"page");
linksFirst = CkJsonObjectW_stringOf(jResp,L"links.first");
linksNext = CkJsonObjectW_stringOf(jResp,L"links.next");
linksPrevious = CkJsonObjectW_stringOf(jResp,L"links.previous");
linksLast = CkJsonObjectW_stringOf(jResp,L"links.last");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"contacts");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
id = CkJsonObjectW_IntOf(jResp,L"contacts[i].id");
title = CkJsonObjectW_stringOf(jResp,L"contacts[i].title");
first_name = CkJsonObjectW_stringOf(jResp,L"contacts[i].first_name");
last_name = CkJsonObjectW_stringOf(jResp,L"contacts[i].last_name");
email = CkJsonObjectW_stringOf(jResp,L"contacts[i].email");
phone_office = CkJsonObjectW_stringOf(jResp,L"contacts[i].phone_office");
phone_mobile = CkJsonObjectW_stringOf(jResp,L"contacts[i].phone_mobile");
fax = CkJsonObjectW_stringOf(jResp,L"contacts[i].fax");
created_at = CkJsonObjectW_stringOf(jResp,L"contacts[i].created_at");
updated_at = CkJsonObjectW_stringOf(jResp,L"contacts[i].updated_at");
clientId = CkJsonObjectW_IntOf(jResp,L"contacts[i].client.id");
clientName = CkJsonObjectW_stringOf(jResp,L"contacts[i].client.name");
i = i + 1;
}
CkHttpW_Dispose(http);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
}