![]() |
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
(DataFlex) SugarCRM: Importing Email Addresses (New Records)Demonstrates how to import a new contact with email addresses. Note: This example requires Chilkat v11.0.0 or greater. For more information, see https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.9/Integration/Migration/Importing_Records/Importing_Email_Addresses/
Use ChilkatAx-win32.pkg Procedure Test Boolean iSuccess Handle hoHttp Variant vJsonRequestBody Handle hoJsonRequestBody String sUrl Variant vResp Handle hoResp Handle hoJsonResponse String sTemp1 Integer iTemp1 Move False To iSuccess // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End Set ComAccept Of hoHttp To "application/json" // The following JSON is sent in the request body: // { // "first_name": "Rob", // "last_name": "Robertson", // "email": [ // { // "email_address": "rob.robertson@sugar.crm", // "primary_address": "1", // "invalid_email": "0", // "opt_out": "0" // }, // { // "email_address": "rob@sugar.crm", // "primary_address": "0", // "invalid_email": "0", // "opt_out": "1" // } // ] // } // Use this online tool to generate the code from sample JSON: // Generate Code to Create JSON Get Create (RefClass(cComChilkatJsonObject)) To hoJsonRequestBody If (Not(IsComObjectCreated(hoJsonRequestBody))) Begin Send CreateComObject of hoJsonRequestBody End Get ComUpdateString Of hoJsonRequestBody "first_name" "Rob" To iSuccess Get ComUpdateString Of hoJsonRequestBody "last_name" "Robertson" To iSuccess Get ComUpdateString Of hoJsonRequestBody "email[0].email_address" "rob.robertson@sugar.crm" To iSuccess Get ComUpdateString Of hoJsonRequestBody "email[0].primary_address" "1" To iSuccess Get ComUpdateString Of hoJsonRequestBody "email[0].invalid_email" "0" To iSuccess Get ComUpdateString Of hoJsonRequestBody "email[0].opt_out" "0" To iSuccess Get ComUpdateString Of hoJsonRequestBody "email[1].email_address" "rob@sugar.crm" To iSuccess Get ComUpdateString Of hoJsonRequestBody "email[1].primary_address" "0" To iSuccess Get ComUpdateString Of hoJsonRequestBody "email[1].invalid_email" "0" To iSuccess Get ComUpdateString Of hoJsonRequestBody "email[1].opt_out" "1" To iSuccess Move "http://<site url>/rest/v10/Contacts" To sUrl Send ComSetRequestHeader To hoHttp "OAuth-Token" "ACCESS_TOKEN" Get Create (RefClass(cComChilkatHttpResponse)) To hoResp If (Not(IsComObjectCreated(hoResp))) Begin Send CreateComObject of hoResp End Get pvComObject of hoJsonRequestBody to vJsonRequestBody Get pvComObject of hoResp to vResp Get ComHttpJson Of hoHttp "POST" sUrl vJsonRequestBody "application/json" vResp To iSuccess If (iSuccess = False) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get ComStatusCode Of hoResp To iTemp1 Showln "Response Status Code: " iTemp1 Get Create (RefClass(cComChilkatJsonObject)) To hoJsonResponse If (Not(IsComObjectCreated(hoJsonResponse))) Begin Send CreateComObject of hoJsonResponse End Get ComBodyStr Of hoResp To sTemp1 Get ComLoad Of hoJsonResponse sTemp1 To iSuccess Set ComEmitCompact Of hoJsonResponse To False Get ComEmit Of hoJsonResponse To sTemp1 Showln sTemp1 Get ComStatusCode Of hoResp To iTemp1 If (iTemp1 >= 300) Begin Showln "Failed." Procedure_Return End End_Procedure |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.