Unicode C++
Unicode C++
GetHarvest - Update Contact
See more GetHarvest Examples
Updates the specific contact by setting the values of the parameters passed. Any parameters not provided will be left unchanged. Returns a contact object and a 200 OK response code if the call succeeded.Chilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
#include <CkHttpResponseW.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;
// Implements the following CURL command:
// curl "https://api.harvestapp.com/v2/contacts/CONTACT_ID" \
// -H "Authorization: Bearer ACCESS_TOKEN" \
// -H "Harvest-Account-Id: ACCOUNT_ID" \
// -H "User-Agent: MyApp (yourname@example.com)" \
// -X PATCH \
// -H "Content-Type: application/json" \
// -d '{"title":"Owner"}'
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "title": "Owner"
// }
CkJsonObjectW json;
json.UpdateString(L"title",L"Owner");
http.SetRequestHeader(L"User-Agent",L"MyApp (yourname@example.com)");
http.SetRequestHeader(L"Content-Type",L"application/json");
http.SetRequestHeader(L"Authorization",L"Bearer ACCESS_TOKEN");
http.SetRequestHeader(L"Harvest-Account-Id",L"ACCOUNT_ID");
CkStringBuilderW sbRequestBody;
json.EmitSb(sbRequestBody);
CkHttpResponseW resp;
success = http.HttpSb(L"PATCH",L"https://api.harvestapp.com/v2/contacts/CONTACT_ID",sbRequestBody,L"utf-8",L"application/json",resp);
if (success == false) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
CkStringBuilderW sbResponseBody;
resp.GetBodySb(sbResponseBody);
CkJsonObjectW jResp;
jResp.LoadSb(sbResponseBody);
jResp.put_EmitCompact(false);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",jResp.emit());
int respStatusCode = resp.get_StatusCode();
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",resp.header());
wprintf(L"Failed.\n");
return;
}
// Sample JSON response:
// {
// "id": 4706510,
// "title": "Owner",
// "first_name": "George",
// "last_name": "Frank",
// "email": "georgefrank@example.com",
// "phone_office": "",
// "phone_mobile": "",
// "fax": "",
// "created_at": "2017-06-26T21:44:57Z",
// "updated_at": "2017-06-26T21:46:48Z",
// "client": {
// "id": 5735776,
// "name": "123 Industries"
// }
// }
// 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 *title = 0;
const wchar_t *first_name = 0;
const wchar_t *last_name = 0;
const wchar_t *email = 0;
const wchar_t *phone_office = 0;
const wchar_t *phone_mobile = 0;
const wchar_t *fax = 0;
const wchar_t *created_at = 0;
const wchar_t *updated_at = 0;
int clientId;
const wchar_t *clientName = 0;
id = jResp.IntOf(L"id");
title = jResp.stringOf(L"title");
first_name = jResp.stringOf(L"first_name");
last_name = jResp.stringOf(L"last_name");
email = jResp.stringOf(L"email");
phone_office = jResp.stringOf(L"phone_office");
phone_mobile = jResp.stringOf(L"phone_mobile");
fax = jResp.stringOf(L"fax");
created_at = jResp.stringOf(L"created_at");
updated_at = jResp.stringOf(L"updated_at");
clientId = jResp.IntOf(L"client.id");
clientName = jResp.stringOf(L"client.name");
}