Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(MFC) 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 <CkHttp.h> #include <CkJsonObject.h> #include <CkHttpResponse.h> #include <CkStringBuilder.h> void ChilkatSample(void) { CkString strOut; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttp http; bool success; // 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" // } CkJsonObject json; json.UpdateString("name","Test Record"); json.UpdateString("email1","test@sugar.com"); http.SetRequestHeader("Cache-Control","no-cache"); http.SetRequestHeader("OAuth-Token","<access_token>"); CkHttpResponse *resp = http.PostJson3("http://<site_url>/rest/v10/Accounts","application/json",json); if (http.get_LastMethodSuccess() == false) { strOut.append(http.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } CkStringBuilder sbResponseBody; resp->GetBodySb(sbResponseBody); CkJsonObject jResp; jResp.LoadSb(sbResponseBody); jResp.put_EmitCompact(false); strOut.append("Response Body:"); strOut.append("\r\n"); strOut.append(jResp.emit()); strOut.append("\r\n"); int respStatusCode = resp->get_StatusCode(); strOut.append("Response Status Code = "); strOut.appendInt(respStatusCode); strOut.append("\r\n"); if (respStatusCode >= 400) { strOut.append("Response Header:"); strOut.append("\r\n"); strOut.append(resp->header()); strOut.append("\r\n"); strOut.append("Failed."); strOut.append("\r\n"); delete resp; SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } delete 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 const char *id = 0; const char *name = 0; const char *date_entered = 0; const char *date_modified = 0; const char *modified_user_id = 0; const char *modified_by_name = 0; const char *modified_user_linkFull_name = 0; const char *modified_user_linkId = 0; const char *modified_user_link_aclDelete = 0; const char *modified_user_link_acl_hash = 0; const char *created_by = 0; const char *created_by_name = 0; const char *created_by_linkFull_name = 0; const char *created_by_linkId = 0; const char *created_by_link_aclDelete = 0; const char *created_by_link_acl_hash = 0; const char *description = 0; bool deleted; const char *facebook = 0; const char *twitter = 0; const char *googleplus = 0; const char *account_type = 0; const char *industry = 0; const char *annual_revenue = 0; const char *phone_fax = 0; const char *billing_address_street = 0; const char *billing_address_street_2 = 0; const char *billing_address_street_3 = 0; const char *billing_address_street_4 = 0; const char *billing_address_city = 0; const char *billing_address_state = 0; const char *billing_address_postalcode = 0; const char *billing_address_country = 0; const char *rating = 0; const char *phone_office = 0; const char *phone_alternate = 0; const char *website = 0; const char *ownership = 0; const char *employees = 0; const char *ticker_symbol = 0; const char *shipping_address_street = 0; const char *shipping_address_street_2 = 0; const char *shipping_address_street_3 = 0; const char *shipping_address_street_4 = 0; const char *shipping_address_city = 0; const char *shipping_address_state = 0; const char *shipping_address_postalcode = 0; const char *shipping_address_country = 0; const char *parent_id = 0; const char *sic_code = 0; const char *duns_num = 0; const char *parent_name = 0; const char *member_ofName = 0; const char *member_ofId = 0; const char *member_of_acl_hash = 0; const char *campaign_id = 0; const char *campaign_name = 0; const char *campaign_accountsName = 0; const char *campaign_accountsId = 0; const char *campaign_accounts_acl_hash = 0; bool following; bool my_favorite; const char *assigned_user_id = 0; const char *assigned_user_name = 0; const char *assigned_user_linkFull_name = 0; const char *assigned_user_linkId = 0; const char *assigned_user_link_acl_hash = 0; const char *team_count = 0; const char *team_count_linkTeam_count = 0; const char *team_count_linkId = 0; const char *team_count_link_acl_hash = 0; const char *email1 = 0; const char *email2 = 0; bool invalid_email; bool email_opt_out; const char *email_addresses_non_primary = 0; const char *v_module = 0; int i; int count_i; int id_int; const char *name_2 = 0; bool primary; const char *email_address = 0; bool opt_out; bool primary_address; bool reply_to_address; id = jResp.stringOf("id"); name = jResp.stringOf("name"); date_entered = jResp.stringOf("date_entered"); date_modified = jResp.stringOf("date_modified"); modified_user_id = jResp.stringOf("modified_user_id"); modified_by_name = jResp.stringOf("modified_by_name"); modified_user_linkFull_name = jResp.stringOf("modified_user_link.full_name"); modified_user_linkId = jResp.stringOf("modified_user_link.id"); modified_user_link_aclDelete = jResp.stringOf("modified_user_link._acl.delete"); modified_user_link_acl_hash = jResp.stringOf("modified_user_link._acl._hash"); created_by = jResp.stringOf("created_by"); created_by_name = jResp.stringOf("created_by_name"); created_by_linkFull_name = jResp.stringOf("created_by_link.full_name"); created_by_linkId = jResp.stringOf("created_by_link.id"); created_by_link_aclDelete = jResp.stringOf("created_by_link._acl.delete"); created_by_link_acl_hash = jResp.stringOf("created_by_link._acl._hash"); description = jResp.stringOf("description"); deleted = jResp.BoolOf("deleted"); facebook = jResp.stringOf("facebook"); twitter = jResp.stringOf("twitter"); googleplus = jResp.stringOf("googleplus"); account_type = jResp.stringOf("account_type"); industry = jResp.stringOf("industry"); annual_revenue = jResp.stringOf("annual_revenue"); phone_fax = jResp.stringOf("phone_fax"); billing_address_street = jResp.stringOf("billing_address_street"); billing_address_street_2 = jResp.stringOf("billing_address_street_2"); billing_address_street_3 = jResp.stringOf("billing_address_street_3"); billing_address_street_4 = jResp.stringOf("billing_address_street_4"); billing_address_city = jResp.stringOf("billing_address_city"); billing_address_state = jResp.stringOf("billing_address_state"); billing_address_postalcode = jResp.stringOf("billing_address_postalcode"); billing_address_country = jResp.stringOf("billing_address_country"); rating = jResp.stringOf("rating"); phone_office = jResp.stringOf("phone_office"); phone_alternate = jResp.stringOf("phone_alternate"); website = jResp.stringOf("website"); ownership = jResp.stringOf("ownership"); employees = jResp.stringOf("employees"); ticker_symbol = jResp.stringOf("ticker_symbol"); shipping_address_street = jResp.stringOf("shipping_address_street"); shipping_address_street_2 = jResp.stringOf("shipping_address_street_2"); shipping_address_street_3 = jResp.stringOf("shipping_address_street_3"); shipping_address_street_4 = jResp.stringOf("shipping_address_street_4"); shipping_address_city = jResp.stringOf("shipping_address_city"); shipping_address_state = jResp.stringOf("shipping_address_state"); shipping_address_postalcode = jResp.stringOf("shipping_address_postalcode"); shipping_address_country = jResp.stringOf("shipping_address_country"); parent_id = jResp.stringOf("parent_id"); sic_code = jResp.stringOf("sic_code"); duns_num = jResp.stringOf("duns_num"); parent_name = jResp.stringOf("parent_name"); member_ofName = jResp.stringOf("member_of.name"); member_ofId = jResp.stringOf("member_of.id"); member_of_acl_hash = jResp.stringOf("member_of._acl._hash"); campaign_id = jResp.stringOf("campaign_id"); campaign_name = jResp.stringOf("campaign_name"); campaign_accountsName = jResp.stringOf("campaign_accounts.name"); campaign_accountsId = jResp.stringOf("campaign_accounts.id"); campaign_accounts_acl_hash = jResp.stringOf("campaign_accounts._acl._hash"); following = jResp.BoolOf("following"); my_favorite = jResp.BoolOf("my_favorite"); assigned_user_id = jResp.stringOf("assigned_user_id"); assigned_user_name = jResp.stringOf("assigned_user_name"); assigned_user_linkFull_name = jResp.stringOf("assigned_user_link.full_name"); assigned_user_linkId = jResp.stringOf("assigned_user_link.id"); assigned_user_link_acl_hash = jResp.stringOf("assigned_user_link._acl._hash"); team_count = jResp.stringOf("team_count"); team_count_linkTeam_count = jResp.stringOf("team_count_link.team_count"); team_count_linkId = jResp.stringOf("team_count_link.id"); team_count_link_acl_hash = jResp.stringOf("team_count_link._acl._hash"); email1 = jResp.stringOf("email1"); email2 = jResp.stringOf("email2"); invalid_email = jResp.BoolOf("invalid_email"); email_opt_out = jResp.BoolOf("email_opt_out"); email_addresses_non_primary = jResp.stringOf("email_addresses_non_primary"); v_module = jResp.stringOf("_module"); i = 0; count_i = jResp.SizeOfArray("modified_user_link._acl.fields"); while (i < count_i) { jResp.put_I(i); i = i + 1; } i = 0; count_i = jResp.SizeOfArray("created_by_link._acl.fields"); while (i < count_i) { jResp.put_I(i); i = i + 1; } i = 0; count_i = jResp.SizeOfArray("member_of._acl.fields"); while (i < count_i) { jResp.put_I(i); i = i + 1; } i = 0; count_i = jResp.SizeOfArray("campaign_accounts._acl.fields"); while (i < count_i) { jResp.put_I(i); i = i + 1; } i = 0; count_i = jResp.SizeOfArray("tag"); while (i < count_i) { jResp.put_I(i); i = i + 1; } i = 0; count_i = jResp.SizeOfArray("assigned_user_link._acl.fields"); while (i < count_i) { jResp.put_I(i); i = i + 1; } i = 0; count_i = jResp.SizeOfArray("team_count_link._acl.fields"); while (i < count_i) { jResp.put_I(i); i = i + 1; } i = 0; count_i = jResp.SizeOfArray("team_name"); while (i < count_i) { jResp.put_I(i); id_int = jResp.IntOf("team_name[i].id"); name = jResp.stringOf("team_name[i].name"); name_2 = jResp.stringOf("team_name[i].name_2"); primary = jResp.BoolOf("team_name[i].primary"); i = i + 1; } i = 0; count_i = jResp.SizeOfArray("email"); while (i < count_i) { jResp.put_I(i); email_address = jResp.stringOf("email[i].email_address"); invalid_email = jResp.BoolOf("email[i].invalid_email"); opt_out = jResp.BoolOf("email[i].opt_out"); primary_address = jResp.BoolOf("email[i].primary_address"); reply_to_address = jResp.BoolOf("email[i].reply_to_address"); i = i + 1; } SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.