AutoIt Requires Chilkat v11.0.0+
AutoIt
Constant Contact V3: Create a contact
See more Constant Contact Examples
Create an account-entered contact and read its new ID. Use the email permission that accurately describes the contact’s relationship with the account. The optional postal address belongs in the street_addresses array. On a duplicate, look up the existing contact before deciding whether an update is appropriate. Authorize the app first and use the same credential store.
Constant Contact developer guide
Chilkat AutoIt Downloads
Local $bSuccess = False
; Assumes Chilkat is unlocked. See Global Unlock Sample.
$oVault = ObjCreate("Chilkat.Secrets")
$oVault.Location = "local_manager"
$oVault.AutoSplit = True
$oEntry = ObjCreate("Chilkat.JsonObject")
$oEntry.UpdateString("appName","ConstantContactV3")
$oEntry.UpdateString("service","OAuth2")
$oEntry.UpdateString("username","my-account")
$oTokens = ObjCreate("Chilkat.JsonObject")
Local $bLoaded = $oVault.GetSecretJson($oEntry,$oTokens)
If ($bLoaded <> True) Then
ConsoleWrite("Run the desktop authorization example using this account and store." & @CRLF)
Exit
EndIf
If ($oTokens.JsonTypeOf("access_token") <> 1) Then
ConsoleWrite("The saved authorization has no access token." & @CRLF)
Exit
EndIf
$oHttp = ObjCreate("Chilkat.Http")
$oHttp.RequireSslCertVerify = True
$oHttp.AuthToken = $oTokens.StringOf("access_token")
$oResp = ObjCreate("Chilkat.HttpResponse")
$oBody = ObjCreate("Chilkat.JsonObject")
$oBody.UpdateString("create_source","Account")
$oBody.UpdateString("first_name","Alex")
$oBody.UpdateString("last_name","Rivera")
$oBody.UpdateString("email_address.address","reader+newsletter@example.com")
; This sample assumes the account has recorded a qualifying existing relationship.
$oBody.UpdateString("email_address.permission_to_send","implicit")
$oBody.UpdateString("street_addresses[0].kind","work")
$oBody.UpdateString("street_addresses[0].street","100 Main Street")
$oBody.UpdateString("street_addresses[0].city","Boston")
$oBody.UpdateString("street_addresses[0].state","MA")
$oBody.UpdateString("street_addresses[0].country","United States")
$bSuccess = $oHttp.HttpJson("POST","https://api.cc.email/v3/contacts",$oBody,"application/json",$oResp)
If ($oResp.StatusCode = 409) Then
ConsoleWrite("Contact already exists. Look up the email address to obtain its ID." & @CRLF)
Exit
EndIf
If (($bSuccess <> True) Or ($oResp.StatusCode <> 201)) Then
ConsoleWrite("Expected HTTP 201. Received " & $oResp.StatusCode & @CRLF)
If ($oResp.StatusCode = 401) Then
ConsoleWrite("Refresh the saved access token or authorize again." & @CRLF)
EndIf
Exit
EndIf
$oCreated = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oCreated.Load($oResp.BodyStr)
If ($bSuccess <> True) Then
ConsoleWrite("Expected a JSON response." & @CRLF)
Exit
EndIf
If (($oCreated.JsonTypeOf("contact_id") <> 1) Or ($oCreated.StringOfEquals("contact_id","",True) = True)) Then
ConsoleWrite("Missing contact_id in the response." & @CRLF)
Exit
EndIf
ConsoleWrite("Created contact ID: " & $oCreated.StringOf("contact_id") & @CRLF)