AutoIt Requires Chilkat v11.0.0+
AutoIt
Constant Contact V3: Find a contact by email address
See more Constant Contact Examples
Look up an exact email address across contact states, including deleted contacts. Pass the address as a query parameter so a literal plus sign survives URL encoding. Read the stored contact ID, email permission, and deletion marker. An empty contacts array means no match. 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")
$oQuery = ObjCreate("Chilkat.HttpRequest")
$oQuery.HttpVerb = "GET"
$oQuery.AddParam "email","reader+newsletter@example.com"
$oQuery.AddParam "status","all"
$bSuccess = $oHttp.HttpReq("https://api.cc.email/v3/contacts",$oQuery,$oResp)
If (($bSuccess <> True) Or ($oResp.StatusCode <> 200)) Then
ConsoleWrite("Expected HTTP 200. Received " & $oResp.StatusCode & @CRLF)
If ($oResp.StatusCode = 401) Then
ConsoleWrite("Refresh the saved access token or authorize again." & @CRLF)
EndIf
Exit
EndIf
$oReply = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oReply.Load($oResp.BodyStr)
If ($bSuccess <> True) Then
ConsoleWrite("Expected a JSON response." & @CRLF)
Exit
EndIf
Local $iCount = $oReply.SizeOfArray("contacts")
If ($iCount < 0) Then
ConsoleWrite("The reply contained no contacts array." & @CRLF)
Exit
EndIf
If ($iCount = 0) Then
ConsoleWrite("No contact has that email address." & @CRLF)
Exit
EndIf
Local $i = 0
While ($i < $iCount)
$oReply.I = $i
ConsoleWrite("Contact ID: " & $oReply.StringOf("contacts[i].contact_id") & @CRLF)
ConsoleWrite("Email permission: " & $oReply.StringOf("contacts[i].email_address.permission_to_send") & @CRLF)
If ($oReply.JsonTypeOf("contacts[i].deleted_at") = 1) Then
ConsoleWrite("Deleted at: " & $oReply.StringOf("contacts[i].deleted_at") & @CRLF)
EndIf
$i = $i + 1
Wend