AutoIt
AutoIt
Constant Contact: Create a Contact
See more Constant Contact Examples
Creates a single contact.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oHttp = ObjCreate("Chilkat.Http")
; 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"
$oResp = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpJson("POST","https://api.cc.email/v3/contacts",$oJson,"application/json",$oResp)
If ($bSuccess = 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")