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
(AutoIt) 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. $oHttp = ObjCreate("Chilkat.Http") Local $bSuccess ; 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" ; } ; } $oJson = ObjCreate("Chilkat.JsonObject") $oJson.UpdateString("email_address.address","danipper@example.com") $oJson.UpdateString("email_address.permission_to_send","implicit") $oJson.UpdateString("first_name","David") $oJson.UpdateString("last_name","Nipper") $oJson.UpdateString("job_title","Musician") $oJson.UpdateString("company_name","Acme Corp.") $oJson.UpdateString("create_source","Account") $oJson.UpdateInt("birthday_month",11) $oJson.UpdateInt("birthday_day",24) $oJson.UpdateString("anniversary","2006-11-15") $oJson.UpdateString("steet_addresses.kind","home") $oJson.UpdateString("steet_addresses.street","123 Kashmir Valley Road") $oJson.UpdateString("steet_addresses.city","Chicago") $oJson.UpdateString("steet_addresses.state","Illinois") $oJson.UpdateString("steet_addresses.country","United States") $oHttp.SetRequestHeader "content-type","application/json" ; Adds the "Authorization: Bearer ACCESS_TOKEN" header. $oHttp.AuthToken = "ACCESS_TOKEN" $oHttp.SetRequestHeader "cache-control","no-cache" $oHttp.SetRequestHeader "accept","application/json" Local $oResp = $oHttp.PostJson3("https://api.cc.email/v3/contacts","application/json",$oJson) If ($oHttp.LastMethodSuccess = False) Then ConsoleWrite($oHttp.LastErrorText & @CRLF) Exit EndIf $oSbResponseBody = ObjCreate("Chilkat.StringBuilder") $oResp.GetBodySb($oSbResponseBody) $oJResp = ObjCreate("Chilkat.JsonObject") $oJResp.LoadSb($oSbResponseBody) $oJResp.EmitCompact = False ConsoleWrite("Response Body:" & @CRLF) ConsoleWrite($oJResp.Emit() & @CRLF) Local $iRespStatusCode = $oResp.StatusCode ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF) If ($iRespStatusCode >= 400) Then ConsoleWrite("Response Header:" & @CRLF) ConsoleWrite($oResp.Header & @CRLF) ConsoleWrite("Failed." & @CRLF) Exit EndIf ; 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 Local $sContact_id = $oJResp.StringOf("contact_id") Local $sEmail_addressAddress = $oJResp.StringOf("email_address.address") Local $sEmail_addressPermission_to_send = $oJResp.StringOf("email_address.permission_to_send") Local $sEmail_addressCreated_at = $oJResp.StringOf("email_address.created_at") Local $sEmail_addressUpdated_at = $oJResp.StringOf("email_address.updated_at") Local $sEmail_addressOpt_in_source = $oJResp.StringOf("email_address.opt_in_source") Local $sEmail_addressOpt_in_date = $oJResp.StringOf("email_address.opt_in_date") Local $sEmail_addressConfirm_status = $oJResp.StringOf("email_address.confirm_status") Local $sFirst_name = $oJResp.StringOf("first_name") Local $sLast_name = $oJResp.StringOf("last_name") Local $sJob_title = $oJResp.StringOf("job_title") Local $sCompany_name = $oJResp.StringOf("company_name") Local $iBirthday_month = $oJResp.IntOf("birthday_month") Local $iBirthday_day = $oJResp.IntOf("birthday_day") Local $sAnniversary = $oJResp.StringOf("anniversary") Local $sCreate_source = $oJResp.StringOf("create_source") Local $sCreated_at = $oJResp.StringOf("created_at") Local $sUpdated_at = $oJResp.StringOf("updated_at") |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.