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 - Update ContactUpdates 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. For more information, see https://help.getharvest.com/api-v2/clients-api/clients/contacts/
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> #include <C_CkStringBuilderW.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkJsonObjectW json; HCkStringBuilderW sbRequestBody; HCkHttpResponseW resp; HCkStringBuilderW sbResponseBody; HCkJsonObjectW jResp; int respStatusCode; 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; // 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/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" // } json = CkJsonObjectW_Create(); CkJsonObjectW_UpdateString(json,L"title",L"Owner"); CkHttpW_SetRequestHeader(http,L"User-Agent",L"MyApp (yourname@example.com)"); CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json"); CkHttpW_SetRequestHeader(http,L"Authorization",L"Bearer ACCESS_TOKEN"); CkHttpW_SetRequestHeader(http,L"Harvest-Account-Id",L"ACCOUNT_ID"); sbRequestBody = CkStringBuilderW_Create(); CkJsonObjectW_EmitSb(json,sbRequestBody); resp = CkHttpW_PTextSb(http,L"PATCH",L"https://api.harvestapp.com/v2/contacts/CONTACT_ID",sbRequestBody,L"utf-8",L"application/json",FALSE,FALSE); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); CkStringBuilderW_Dispose(sbRequestBody); return; } sbResponseBody = CkStringBuilderW_Create(); CkHttpResponseW_GetBodySb(resp,sbResponseBody); jResp = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(jResp,sbResponseBody); CkJsonObjectW_putEmitCompact(jResp,FALSE); wprintf(L"Response Body:\n"); wprintf(L"%s\n",CkJsonObjectW_emit(jResp)); respStatusCode = CkHttpResponseW_getStatusCode(resp); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",CkHttpResponseW_header(resp)); wprintf(L"Failed.\n"); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); CkStringBuilderW_Dispose(sbRequestBody); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); return; } CkHttpResponseW_Dispose(resp); // 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 id = CkJsonObjectW_IntOf(jResp,L"id"); title = CkJsonObjectW_stringOf(jResp,L"title"); first_name = CkJsonObjectW_stringOf(jResp,L"first_name"); last_name = CkJsonObjectW_stringOf(jResp,L"last_name"); email = CkJsonObjectW_stringOf(jResp,L"email"); phone_office = CkJsonObjectW_stringOf(jResp,L"phone_office"); phone_mobile = CkJsonObjectW_stringOf(jResp,L"phone_mobile"); fax = CkJsonObjectW_stringOf(jResp,L"fax"); created_at = CkJsonObjectW_stringOf(jResp,L"created_at"); updated_at = CkJsonObjectW_stringOf(jResp,L"updated_at"); clientId = CkJsonObjectW_IntOf(jResp,L"client.id"); clientName = CkJsonObjectW_stringOf(jResp,L"client.name"); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); CkStringBuilderW_Dispose(sbRequestBody); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.