Sample code for 30+ languages & platforms
VBScript Requires Chilkat v11.0.0+

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 VBScript Downloads

VBScript
Dim fso, outFile
Set fso = CreateObject("Scripting.FileSystemObject")
'Create a Unicode (utf-16) output text file.
Set outFile = fso.CreateTextFile("output.txt", True, True)

success = 0

'  Assumes Chilkat is unlocked. See Global Unlock Sample.
set vault = CreateObject("Chilkat.Secrets")
vault.Location = "local_manager"
vault.AutoSplit = 1
set entry = CreateObject("Chilkat.JsonObject")
success = entry.UpdateString("appName","ConstantContactV3")
success = entry.UpdateString("service","OAuth2")
success = entry.UpdateString("username","my-account")
set tokens = CreateObject("Chilkat.JsonObject")
loaded = vault.GetSecretJson(entry,tokens)
If (loaded <> 1) Then
    outFile.WriteLine("Run the desktop authorization example using this account and store.")
    WScript.Quit
End If

If (tokens.JsonTypeOf("access_token") <> 1) Then
    outFile.WriteLine("The saved authorization has no access token.")
    WScript.Quit
End If

set http = CreateObject("Chilkat.Http")
http.RequireSslCertVerify = 1
http.AuthToken = tokens.StringOf("access_token")
set resp = CreateObject("Chilkat.HttpResponse")

success = http.SetUrlVar("list","LIST_ID")
set url = CreateObject("Chilkat.StringBuilder")
success = url.Append("https://api.cc.email/v3/contacts?lists={$list}&limit=50")
set page = CreateObject("Chilkat.JsonObject")
total = 0
Do While (url.Length > 0)
    success = http.HttpNoBody("GET",url.GetAsString(),resp)
    If ((success <> 1) Or (resp.StatusCode <> 200)) Then
        outFile.WriteLine("Expected HTTP 200. Received " & resp.StatusCode)
        If (resp.StatusCode = 401) Then
            outFile.WriteLine("Refresh the saved access token or authorize again.")
        End If

        WScript.Quit
    End If

    success = page.Load(resp.BodyStr)
    count = page.SizeOfArray("contacts")
    If ((success <> 1) Or (count < 0)) Then
        outFile.WriteLine("Expected a page of contacts.")
        WScript.Quit
    End If

    i = 0
    Do While (i < count)
        page.I = i
        outFile.WriteLine(page.StringOf("contacts[i].contact_id") & "  " & page.StringOf("contacts[i].email_address.address"))
        i = i + 1
    Loop
    total = total + count
    url.Clear 
    If (page.JsonTypeOf("_links.next.href") = 1) Then
        success = url.Append(page.StringOf("_links.next.href"))
        '  The documented cursor link is relative to api.cc.email.
        If (url.StartsWith("/v3/contacts?",1) <> 1) Then
            outFile.WriteLine("Unexpected pagination link. Stopped before following it.")
            WScript.Quit
        End If

        success = url.Prepend("https://api.cc.email")
    End If

Loop
outFile.WriteLine("List members read: " & total)

outFile.Close