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 - Create ContactCreates a new contact object. Returns a contact object and a 201 Created response code if the call succeeded. For more information, see https://help.getharvest.com/api-v2/clients-api/clients/contacts/
#include <CkHttpW.h> #include <CkJsonObjectW.h> #include <CkHttpResponseW.h> #include <CkStringBuilderW.h> void ChilkatSample(void) { // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttpW http; bool success; // 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)" \ // -X POST \ // -H "Content-Type: application/json" \ // -d '{"client_id":8282839,"first_name":"George","last_name":"Frank","email":"georgefrank@example.com"}' // Use this online tool to generate code from sample JSON: // Generate Code to Create JSON // The following JSON is sent in the request body. // { // "client_id": 8282839, // "first_name": "George", // "last_name": "Frank", // "email": "georgefrank@example.com" // } CkJsonObjectW json; json.UpdateInt(L"client_id",8282839); json.UpdateString(L"first_name",L"George"); json.UpdateString(L"last_name",L"Frank"); json.UpdateString(L"email",L"georgefrank@example.com"); 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"); CkHttpResponseW *resp = http.PostJson3(L"https://api.harvestapp.com/v2/contacts",L"application/json",json); if (http.get_LastMethodSuccess() == 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"); delete resp; return; } delete resp; // Sample JSON response: // { // "id": 4706510, // "title": null, // "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:44:57Z", // "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"); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.