AutoIt Requires Chilkat v11.0.0+
AutoIt
Constant Contact V3: Read every page of list members
See more Constant Contact Examples
Filter the contacts collection with lists and a list ID. To query multiple lists together, supply their comma-separated IDs. Follow the returned cursor links and report the total after the last page. The default contacts query excludes deleted records. A list member can still have unsubscribed email permission. 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")
$oHttp.SetUrlVar("list","LIST_ID")
$oUrl = ObjCreate("Chilkat.StringBuilder")
$oUrl.Append("https://api.cc.email/v3/contacts?lists={$list}&limit=50")
$oPage = ObjCreate("Chilkat.JsonObject")
Local $iTotal = 0
While ($oUrl.Length > 0)
$bSuccess = $oHttp.HttpNoBody("GET",$oUrl.GetAsString(),$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
$bSuccess = $oPage.Load($oResp.BodyStr)
Local $iCount = $oPage.SizeOfArray("contacts")
If (($bSuccess <> True) Or ($iCount < 0)) Then
ConsoleWrite("Expected a page of contacts." & @CRLF)
Exit
EndIf
Local $i = 0
While ($i < $iCount)
$oPage.I = $i
ConsoleWrite($oPage.StringOf("contacts[i].contact_id") & " " & $oPage.StringOf("contacts[i].email_address.address") & @CRLF)
$i = $i + 1
Wend
$iTotal = $iTotal + $iCount
$oUrl.Clear
If ($oPage.JsonTypeOf("_links.next.href") = 1) Then
$oUrl.Append($oPage.StringOf("_links.next.href"))
; The documented cursor link is relative to api.cc.email.
If ($oUrl.StartsWith("/v3/contacts?",True) <> True) Then
ConsoleWrite("Unexpected pagination link. Stopped before following it." & @CRLF)
Exit
EndIf
$oUrl.Prepend("https://api.cc.email")
EndIf
Wend
ConsoleWrite("List members read: " & $iTotal & @CRLF)