AutoIt Requires Chilkat v11.0.0+
AutoIt
Constant Contact V3: Find a contact list by name
See more Constant Contact Examples
Start with the full list name from the Constant Contact account. Read its list_id and the number of active, mailable contacts. Use the ID for list membership operations or campaign targeting. This lookup requires contact_data.
Authorize the application using the same account and 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")
; Use the full display name. AddParam encodes spaces and punctuation.
Local $sListName = "Workshop announcements"
$oQuery = ObjCreate("Chilkat.HttpRequest")
$oQuery.HttpVerb = "GET"
$oQuery.AddParam "name",$sListName
$oQuery.AddParam "status","active"
$oQuery.AddParam "include_membership_count","active"
$bSuccess = $oHttp.HttpReq("https://api.cc.email/v3/contact_lists",$oQuery,$oResp)
If (($bSuccess <> True) And ($oResp.StatusCode <= 0)) Then
ConsoleWrite("Look up list: HTTP request failed." & @CRLF)
Exit
EndIf
If (($bSuccess <> True) Or ($oResp.StatusCode <> 200)) Then
ConsoleWrite("Look up list: HTTP " & $oResp.StatusCode & " " & $oResp.BodyStr & @CRLF)
Exit
EndIf
$oMatches = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oMatches.Load($oResp.BodyStr)
If ($bSuccess <> True) Then
ConsoleWrite("Expected a JSON object in the response." & @CRLF)
Exit
EndIf
If ($oMatches.SizeOfArray("lists") = 0) Then
ConsoleWrite("No active email list named " & $sListName & @CRLF)
Exit
EndIf
If (($oMatches.SizeOfArray("lists") <> 1) Or ($oMatches.StringOfEquals("lists[0].name",$sListName,True) <> True)) Then
ConsoleWrite("Expected one exact list name." & @CRLF)
Exit
EndIf
Local $sListId = $oMatches.StringOf("lists[0].list_id")
If ($sListId = "") Then
ConsoleWrite("Missing list ID." & @CRLF)
Exit
EndIf
ConsoleWrite($sListName & " | List ID: " & $sListId & " | Mailable contacts: " & $oMatches.IntOf("lists[0].membership_count") & @CRLF)