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
(Lianja) Constant Contact: Create a ContactCreates a single contact. For more information, see https://v3.developer.constantcontact.com/api_guide/contacts_create.html#cURL2
// This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loHttp = createobject("CkHttp") // Implements the following CURL command: // curl -X POST \ // https://api.cc.email/v3/contacts \ // -H 'accept: application/json' \ // -H 'authorization: Bearer {access_token}' \ // -H 'cache-control: no-cache' \ // -H 'content-type: application/json' \ // -d '{ // "email_address": { // "address": "danipper@example.com", // "permission_to_send": "implicit" // }, // "first_name": "David", // "last_name": "Nipper", // "job_title": "Musician", // "company_name": "Acme Corp.", // "create_source": "Account", // "birthday_month": 11, // "birthday_day": 24, // "anniversary": "2006-11-15", // "steet_addresses":{ // "kind":"home", // "street": "123 Kashmir Valley Road", // "city": "Chicago", // "state": "Illinois", // "country": "United States", // } // }' // Use the following online tool to generate HTTP code from a CURL command // Convert a cURL Command to HTTP Source Code // Use this online tool to generate code from sample JSON: // Generate Code to Create JSON // The following JSON is sent in the request body. // { // "email_address": { // "address": "danipper@example.com", // "permission_to_send": "implicit" // }, // "first_name": "David", // "last_name": "Nipper", // "job_title": "Musician", // "company_name": "Acme Corp.", // "create_source": "Account", // "birthday_month": 11, // "birthday_day": 24, // "anniversary": "2006-11-15", // "steet_addresses": { // "kind": "home", // "street": "123 Kashmir Valley Road", // "city": "Chicago", // "state": "Illinois", // "country": "United States" // } // } loJson = createobject("CkJsonObject") loJson.UpdateString("email_address.address","danipper@example.com") loJson.UpdateString("email_address.permission_to_send","implicit") loJson.UpdateString("first_name","David") loJson.UpdateString("last_name","Nipper") loJson.UpdateString("job_title","Musician") loJson.UpdateString("company_name","Acme Corp.") loJson.UpdateString("create_source","Account") loJson.UpdateInt("birthday_month",11) loJson.UpdateInt("birthday_day",24) loJson.UpdateString("anniversary","2006-11-15") loJson.UpdateString("steet_addresses.kind","home") loJson.UpdateString("steet_addresses.street","123 Kashmir Valley Road") loJson.UpdateString("steet_addresses.city","Chicago") loJson.UpdateString("steet_addresses.state","Illinois") loJson.UpdateString("steet_addresses.country","United States") loHttp.SetRequestHeader("content-type","application/json") // Adds the "Authorization: Bearer ACCESS_TOKEN" header. loHttp.AuthToken = "ACCESS_TOKEN" loHttp.SetRequestHeader("cache-control","no-cache") loHttp.SetRequestHeader("accept","application/json") loResp = loHttp.PostJson3("https://api.cc.email/v3/contacts","application/json",loJson) if (loHttp.LastMethodSuccess = .F.) then ? loHttp.LastErrorText release loHttp release loJson return endif loSbResponseBody = createobject("CkStringBuilder") loResp.GetBodySb(loSbResponseBody) loJResp = createobject("CkJsonObject") loJResp.LoadSb(loSbResponseBody) loJResp.EmitCompact = .F. ? "Response Body:" ? loJResp.Emit() lnRespStatusCode = loResp.StatusCode ? "Response Status Code = " + str(lnRespStatusCode) if (lnRespStatusCode >= 400) then ? "Response Header:" ? loResp.Header ? "Failed." release loResp release loHttp release loJson release loSbResponseBody release loJResp return endif release loResp // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "contact_id": "{contact_id}", // "email_address": { // "address": "danipper@example.com", // "permission_to_send": "implicit", // "created_at": "2018-02-23T13:38:28-05:00", // "updated_at": "2018-02-23T13:38:28-05:00", // "opt_in_source": "Account", // "opt_in_date": "2018-02-23T13:38:28-05:00", // "confirm_status": "off" // }, // "first_name": "David", // "last_name": "Nipper", // "job_title": "Musician", // "company_name": "Acme Corp.", // "birthday_month": 11, // "birthday_day": 24, // "anniversary": "2006-11-15", // "create_source": "Account", // "created_at": "2018-02-23T13:38:28-05:00", // "updated_at": "2018-02-23T13:38:28-05:00" // } // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON lcContact_id = loJResp.StringOf("contact_id") lcEmail_addressAddress = loJResp.StringOf("email_address.address") lcEmail_addressPermission_to_send = loJResp.StringOf("email_address.permission_to_send") lcEmail_addressCreated_at = loJResp.StringOf("email_address.created_at") lcEmail_addressUpdated_at = loJResp.StringOf("email_address.updated_at") lcEmail_addressOpt_in_source = loJResp.StringOf("email_address.opt_in_source") lcEmail_addressOpt_in_date = loJResp.StringOf("email_address.opt_in_date") lcEmail_addressConfirm_status = loJResp.StringOf("email_address.confirm_status") lcFirst_name = loJResp.StringOf("first_name") lcLast_name = loJResp.StringOf("last_name") lcJob_title = loJResp.StringOf("job_title") lcCompany_name = loJResp.StringOf("company_name") lnBirthday_month = loJResp.IntOf("birthday_month") lnBirthday_day = loJResp.IntOf("birthday_day") lcAnniversary = loJResp.StringOf("anniversary") lcCreate_source = loJResp.StringOf("create_source") lcCreated_at = loJResp.StringOf("created_at") lcUpdated_at = loJResp.StringOf("updated_at") release loHttp release loJson release loSbResponseBody release loJResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.