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) SugarCRM Create a RecordSubmit a record to the Sugar instance using the / For more information, see https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.9/Integration/Web_Services/v10/Examples/Bash/How_to_Manipulate_Records_CRUD/#Creating_a_Record
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> #include <C_CkHttpResponseW.h> #include <C_CkStringBuilderW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkJsonObjectW json; HCkHttpResponseW resp; HCkStringBuilderW sbResponseBody; HCkJsonObjectW jResp; int respStatusCode; const wchar_t *id; const wchar_t *name; const wchar_t *date_entered; const wchar_t *date_modified; const wchar_t *modified_user_id; const wchar_t *modified_by_name; const wchar_t *modified_user_linkFull_name; const wchar_t *modified_user_linkId; const wchar_t *modified_user_link_aclDelete; const wchar_t *modified_user_link_acl_hash; const wchar_t *created_by; const wchar_t *created_by_name; const wchar_t *created_by_linkFull_name; const wchar_t *created_by_linkId; const wchar_t *created_by_link_aclDelete; const wchar_t *created_by_link_acl_hash; const wchar_t *description; BOOL deleted; const wchar_t *facebook; const wchar_t *twitter; const wchar_t *googleplus; const wchar_t *account_type; const wchar_t *industry; const wchar_t *annual_revenue; const wchar_t *phone_fax; const wchar_t *billing_address_street; const wchar_t *billing_address_street_2; const wchar_t *billing_address_street_3; const wchar_t *billing_address_street_4; const wchar_t *billing_address_city; const wchar_t *billing_address_state; const wchar_t *billing_address_postalcode; const wchar_t *billing_address_country; const wchar_t *rating; const wchar_t *phone_office; const wchar_t *phone_alternate; const wchar_t *website; const wchar_t *ownership; const wchar_t *employees; const wchar_t *ticker_symbol; const wchar_t *shipping_address_street; const wchar_t *shipping_address_street_2; const wchar_t *shipping_address_street_3; const wchar_t *shipping_address_street_4; const wchar_t *shipping_address_city; const wchar_t *shipping_address_state; const wchar_t *shipping_address_postalcode; const wchar_t *shipping_address_country; const wchar_t *parent_id; const wchar_t *sic_code; const wchar_t *duns_num; const wchar_t *parent_name; const wchar_t *member_ofName; const wchar_t *member_ofId; const wchar_t *member_of_acl_hash; const wchar_t *campaign_id; const wchar_t *campaign_name; const wchar_t *campaign_accountsName; const wchar_t *campaign_accountsId; const wchar_t *campaign_accounts_acl_hash; BOOL following; BOOL my_favorite; const wchar_t *assigned_user_id; const wchar_t *assigned_user_name; const wchar_t *assigned_user_linkFull_name; const wchar_t *assigned_user_linkId; const wchar_t *assigned_user_link_acl_hash; const wchar_t *team_count; const wchar_t *team_count_linkTeam_count; const wchar_t *team_count_linkId; const wchar_t *team_count_link_acl_hash; const wchar_t *email1; const wchar_t *email2; BOOL invalid_email; BOOL email_opt_out; const wchar_t *email_addresses_non_primary; const wchar_t *v_module; int i; int count_i; int id_int; const wchar_t *name_2; BOOL primary; const wchar_t *email_address; BOOL opt_out; BOOL primary_address; BOOL reply_to_address; // 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 -X POST -H OAuth-Token:<access_token> -H Cache-Control:no-cache -d '{ // "name":"Test Record", // "email1":"test@sugar.com" // }' http://<site_url>/rest/v10/Accounts // Use this online tool to generate code from sample JSON: // Generate Code to Create JSON // The following JSON is sent in the request body. // { // "name": "Test Record", // "email1": "test@sugar.com" // } json = CkJsonObjectW_Create(); CkJsonObjectW_UpdateString(json,L"name",L"Test Record"); CkJsonObjectW_UpdateString(json,L"email1",L"test@sugar.com"); CkHttpW_SetRequestHeader(http,L"Cache-Control",L"no-cache"); CkHttpW_SetRequestHeader(http,L"OAuth-Token",L"<access_token>"); resp = CkHttpW_PostJson3(http,L"http://<site_url>/rest/v10/Accounts",L"application/json",json); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); 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(sbResponseBody); CkJsonObjectW_Dispose(jResp); return; } CkHttpResponseW_Dispose(resp); // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "id": "ab2222df-73da-0e92-6887-5705428f4d68", // "name": "Test Record", // "date_entered": "2016-04-06T13:07:41-04:00", // "date_modified": "2016-04-06T13:07:41-04:00", // "modified_user_id": "1", // "modified_by_name": "Administrator", // "modified_user_link": { // "full_name": "Administrator", // "id": "1", // "_acl": { // "fields": [ // ], // "delete": "no", // "_hash": "8e11bf9be8f04daddee9d08d44ea891e" // } // }, // "created_by": "1", // "created_by_name": "Administrator", // "created_by_link": { // "full_name": "Administrator", // "id": "1", // "_acl": { // "fields": [ // ], // "delete": "no", // "_hash": "8e11bf9be8f04daddee9d08d44ea891e" // } // }, // "description": "", // "deleted": false, // "facebook": "", // "twitter": "", // "googleplus": "", // "account_type": "", // "industry": "", // "annual_revenue": "", // "phone_fax": "", // "billing_address_street": "", // "billing_address_street_2": "", // "billing_address_street_3": "", // "billing_address_street_4": "", // "billing_address_city": "", // "billing_address_state": "", // "billing_address_postalcode": "", // "billing_address_country": "", // "rating": "", // "phone_office": "", // "phone_alternate": "", // "website": "", // "ownership": "", // "employees": "", // "ticker_symbol": "", // "shipping_address_street": "", // "shipping_address_street_2": "", // "shipping_address_street_3": "", // "shipping_address_street_4": "", // "shipping_address_city": "", // "shipping_address_state": "", // "shipping_address_postalcode": "", // "shipping_address_country": "", // "parent_id": "", // "sic_code": "", // "duns_num": "", // "parent_name": "", // "member_of": { // "name": "", // "id": "", // "_acl": { // "fields": [ // ], // "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" // } // }, // "campaign_id": "", // "campaign_name": "", // "campaign_accounts": { // "name": "", // "id": "", // "_acl": { // "fields": [ // ], // "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" // } // }, // "following": true, // "my_favorite": false, // "tag": [ // ], // "assigned_user_id": "", // "assigned_user_name": "", // "assigned_user_link": { // "full_name": "", // "id": "", // "_acl": { // "fields": [ // ], // "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" // } // }, // "team_count": "", // "team_count_link": { // "team_count": "", // "id": "1", // "_acl": { // "fields": [ // ], // "_hash": "654d337e0e912edaa00dbb0fb3dc3c17" // } // }, // "team_name": [ // { // "id": 1, // "name": "Global", // "name_2": "", // "primary": true // } // ], // "email": [ // { // "email_address": "test@sugar.com", // "invalid_email": false, // "opt_out": false, // "primary_address": true, // "reply_to_address": false // } // ], // "email1": "test@sugar.com", // "email2": "", // "invalid_email": false, // "email_opt_out": false, // "email_addresses_non_primary": "", // "_acl": { // "fields": {} // }, // "_module": "Accounts" // } // 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_stringOf(jResp,L"id"); name = CkJsonObjectW_stringOf(jResp,L"name"); date_entered = CkJsonObjectW_stringOf(jResp,L"date_entered"); date_modified = CkJsonObjectW_stringOf(jResp,L"date_modified"); modified_user_id = CkJsonObjectW_stringOf(jResp,L"modified_user_id"); modified_by_name = CkJsonObjectW_stringOf(jResp,L"modified_by_name"); modified_user_linkFull_name = CkJsonObjectW_stringOf(jResp,L"modified_user_link.full_name"); modified_user_linkId = CkJsonObjectW_stringOf(jResp,L"modified_user_link.id"); modified_user_link_aclDelete = CkJsonObjectW_stringOf(jResp,L"modified_user_link._acl.delete"); modified_user_link_acl_hash = CkJsonObjectW_stringOf(jResp,L"modified_user_link._acl._hash"); created_by = CkJsonObjectW_stringOf(jResp,L"created_by"); created_by_name = CkJsonObjectW_stringOf(jResp,L"created_by_name"); created_by_linkFull_name = CkJsonObjectW_stringOf(jResp,L"created_by_link.full_name"); created_by_linkId = CkJsonObjectW_stringOf(jResp,L"created_by_link.id"); created_by_link_aclDelete = CkJsonObjectW_stringOf(jResp,L"created_by_link._acl.delete"); created_by_link_acl_hash = CkJsonObjectW_stringOf(jResp,L"created_by_link._acl._hash"); description = CkJsonObjectW_stringOf(jResp,L"description"); deleted = CkJsonObjectW_BoolOf(jResp,L"deleted"); facebook = CkJsonObjectW_stringOf(jResp,L"facebook"); twitter = CkJsonObjectW_stringOf(jResp,L"twitter"); googleplus = CkJsonObjectW_stringOf(jResp,L"googleplus"); account_type = CkJsonObjectW_stringOf(jResp,L"account_type"); industry = CkJsonObjectW_stringOf(jResp,L"industry"); annual_revenue = CkJsonObjectW_stringOf(jResp,L"annual_revenue"); phone_fax = CkJsonObjectW_stringOf(jResp,L"phone_fax"); billing_address_street = CkJsonObjectW_stringOf(jResp,L"billing_address_street"); billing_address_street_2 = CkJsonObjectW_stringOf(jResp,L"billing_address_street_2"); billing_address_street_3 = CkJsonObjectW_stringOf(jResp,L"billing_address_street_3"); billing_address_street_4 = CkJsonObjectW_stringOf(jResp,L"billing_address_street_4"); billing_address_city = CkJsonObjectW_stringOf(jResp,L"billing_address_city"); billing_address_state = CkJsonObjectW_stringOf(jResp,L"billing_address_state"); billing_address_postalcode = CkJsonObjectW_stringOf(jResp,L"billing_address_postalcode"); billing_address_country = CkJsonObjectW_stringOf(jResp,L"billing_address_country"); rating = CkJsonObjectW_stringOf(jResp,L"rating"); phone_office = CkJsonObjectW_stringOf(jResp,L"phone_office"); phone_alternate = CkJsonObjectW_stringOf(jResp,L"phone_alternate"); website = CkJsonObjectW_stringOf(jResp,L"website"); ownership = CkJsonObjectW_stringOf(jResp,L"ownership"); employees = CkJsonObjectW_stringOf(jResp,L"employees"); ticker_symbol = CkJsonObjectW_stringOf(jResp,L"ticker_symbol"); shipping_address_street = CkJsonObjectW_stringOf(jResp,L"shipping_address_street"); shipping_address_street_2 = CkJsonObjectW_stringOf(jResp,L"shipping_address_street_2"); shipping_address_street_3 = CkJsonObjectW_stringOf(jResp,L"shipping_address_street_3"); shipping_address_street_4 = CkJsonObjectW_stringOf(jResp,L"shipping_address_street_4"); shipping_address_city = CkJsonObjectW_stringOf(jResp,L"shipping_address_city"); shipping_address_state = CkJsonObjectW_stringOf(jResp,L"shipping_address_state"); shipping_address_postalcode = CkJsonObjectW_stringOf(jResp,L"shipping_address_postalcode"); shipping_address_country = CkJsonObjectW_stringOf(jResp,L"shipping_address_country"); parent_id = CkJsonObjectW_stringOf(jResp,L"parent_id"); sic_code = CkJsonObjectW_stringOf(jResp,L"sic_code"); duns_num = CkJsonObjectW_stringOf(jResp,L"duns_num"); parent_name = CkJsonObjectW_stringOf(jResp,L"parent_name"); member_ofName = CkJsonObjectW_stringOf(jResp,L"member_of.name"); member_ofId = CkJsonObjectW_stringOf(jResp,L"member_of.id"); member_of_acl_hash = CkJsonObjectW_stringOf(jResp,L"member_of._acl._hash"); campaign_id = CkJsonObjectW_stringOf(jResp,L"campaign_id"); campaign_name = CkJsonObjectW_stringOf(jResp,L"campaign_name"); campaign_accountsName = CkJsonObjectW_stringOf(jResp,L"campaign_accounts.name"); campaign_accountsId = CkJsonObjectW_stringOf(jResp,L"campaign_accounts.id"); campaign_accounts_acl_hash = CkJsonObjectW_stringOf(jResp,L"campaign_accounts._acl._hash"); following = CkJsonObjectW_BoolOf(jResp,L"following"); my_favorite = CkJsonObjectW_BoolOf(jResp,L"my_favorite"); assigned_user_id = CkJsonObjectW_stringOf(jResp,L"assigned_user_id"); assigned_user_name = CkJsonObjectW_stringOf(jResp,L"assigned_user_name"); assigned_user_linkFull_name = CkJsonObjectW_stringOf(jResp,L"assigned_user_link.full_name"); assigned_user_linkId = CkJsonObjectW_stringOf(jResp,L"assigned_user_link.id"); assigned_user_link_acl_hash = CkJsonObjectW_stringOf(jResp,L"assigned_user_link._acl._hash"); team_count = CkJsonObjectW_stringOf(jResp,L"team_count"); team_count_linkTeam_count = CkJsonObjectW_stringOf(jResp,L"team_count_link.team_count"); team_count_linkId = CkJsonObjectW_stringOf(jResp,L"team_count_link.id"); team_count_link_acl_hash = CkJsonObjectW_stringOf(jResp,L"team_count_link._acl._hash"); email1 = CkJsonObjectW_stringOf(jResp,L"email1"); email2 = CkJsonObjectW_stringOf(jResp,L"email2"); invalid_email = CkJsonObjectW_BoolOf(jResp,L"invalid_email"); email_opt_out = CkJsonObjectW_BoolOf(jResp,L"email_opt_out"); email_addresses_non_primary = CkJsonObjectW_stringOf(jResp,L"email_addresses_non_primary"); v_module = CkJsonObjectW_stringOf(jResp,L"_module"); i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"modified_user_link._acl.fields"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"created_by_link._acl.fields"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"member_of._acl.fields"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"campaign_accounts._acl.fields"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"tag"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"assigned_user_link._acl.fields"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"team_count_link._acl.fields"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"team_name"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); id_int = CkJsonObjectW_IntOf(jResp,L"team_name[i].id"); name = CkJsonObjectW_stringOf(jResp,L"team_name[i].name"); name_2 = CkJsonObjectW_stringOf(jResp,L"team_name[i].name_2"); primary = CkJsonObjectW_BoolOf(jResp,L"team_name[i].primary"); i = i + 1; } i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"email"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); email_address = CkJsonObjectW_stringOf(jResp,L"email[i].email_address"); invalid_email = CkJsonObjectW_BoolOf(jResp,L"email[i].invalid_email"); opt_out = CkJsonObjectW_BoolOf(jResp,L"email[i].opt_out"); primary_address = CkJsonObjectW_BoolOf(jResp,L"email[i].primary_address"); reply_to_address = CkJsonObjectW_BoolOf(jResp,L"email[i].reply_to_address"); i = i + 1; } CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.