![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C) Activix CRM Create a PhoneCreate a phone. Returns the created phone. Note: This example requires Chilkat v11.0.0 or greater. For more information, see https://docs.crm.activix.ca/api/resources/phone
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { BOOL success; HCkHttpW http; HCkJsonObjectW jsonRequestBody; const wchar_t *url; HCkHttpResponseW resp; HCkJsonObjectW jsonResponse; int dataId; const wchar_t *dataCreated_at; const wchar_t *dataUpdated_at; int dataLead_id; const wchar_t *dataExtension; const wchar_t *dataNumber; const wchar_t *dataType; BOOL dataValid; const wchar_t *dataValidated; BOOL dataMobile; success = FALSE; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); CkHttpW_putAuthToken(http,L"ACCESS_TOKEN"); CkHttpW_putAccept(http,L"application/json"); // The following JSON is sent in the request body: // { // "lead_id": 7135833, // "number": "+15141234455", // "type": "home" // } // Use this online tool to generate the code from sample JSON: // Generate Code to Create JSON jsonRequestBody = CkJsonObjectW_Create(); CkJsonObjectW_UpdateInt(jsonRequestBody,L"lead_id",7135833); CkJsonObjectW_UpdateString(jsonRequestBody,L"number",L"+15141234455"); CkJsonObjectW_UpdateString(jsonRequestBody,L"type",L"home"); url = L"https://crm.activix.ca/api/v2/lead-phones"; resp = CkHttpResponseW_Create(); success = CkHttpW_HttpJson(http,L"POST",url,jsonRequestBody,L"application/json",resp); if (success == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonRequestBody); CkHttpResponseW_Dispose(resp); return; } wprintf(L"Response Status Code: %d\n",CkHttpResponseW_getStatusCode(resp)); jsonResponse = CkJsonObjectW_Create(); CkJsonObjectW_Load(jsonResponse,CkHttpResponseW_bodyStr(resp)); CkJsonObjectW_putEmitCompact(jsonResponse,FALSE); wprintf(L"%s\n",CkJsonObjectW_emit(jsonResponse)); if (CkHttpResponseW_getStatusCode(resp) >= 300) { wprintf(L"Failed.\n"); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonRequestBody); CkHttpResponseW_Dispose(resp); CkJsonObjectW_Dispose(jsonResponse); return; } // Sample output... // (See the parsing code below..) // // Use the this online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON // { // "data": { // "id": 34566, // "created_at": "2018-04-09T18:05:00+00:00", // "updated_at": "2018-04-09T18:05:00+00:00", // "lead_id": 3466512, // "number": "+15141234455", // ... // } // } dataId = CkJsonObjectW_IntOf(jsonResponse,L"data.id"); dataCreated_at = CkJsonObjectW_stringOf(jsonResponse,L"data.created_at"); dataUpdated_at = CkJsonObjectW_stringOf(jsonResponse,L"data.updated_at"); dataLead_id = CkJsonObjectW_IntOf(jsonResponse,L"data.lead_id"); dataExtension = CkJsonObjectW_stringOf(jsonResponse,L"data.extension"); dataNumber = CkJsonObjectW_stringOf(jsonResponse,L"data.number"); dataType = CkJsonObjectW_stringOf(jsonResponse,L"data.type"); dataValid = CkJsonObjectW_BoolOf(jsonResponse,L"data.valid"); dataValidated = CkJsonObjectW_stringOf(jsonResponse,L"data.validated"); dataMobile = CkJsonObjectW_BoolOf(jsonResponse,L"data.mobile"); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonRequestBody); CkHttpResponseW_Dispose(resp); CkJsonObjectW_Dispose(jsonResponse); } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.