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

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

B4X
Dim success As Boolean = False

'  Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim vault As ChilkatSecrets
vault.Initialize("vault")
vault.Location = "local_manager"
vault.AutoSplit = True
Dim entry As ChilkatJsonObject
entry.Initialize
entry.UpdateString("appName", "ConstantContactV3")
entry.UpdateString("service", "OAuth2")
entry.UpdateString("username", "my-account")
Dim tokens As ChilkatJsonObject
tokens.Initialize
Dim loaded As Boolean = vault.GetSecretJson(entry, tokens)
If loaded <> True Then
    Log("Run the desktop authorization example using this account and store.")
    Return
End If

If tokens.JsonTypeOf("access_token") <> 1 Then
    Log("The saved authorization has no access token.")
    Return
End If

Dim http As ChilkatHttp
http.Initialize("http")
http.RequireSslCertVerify = True
http.AuthToken = tokens.StringOf("access_token")
Dim resp As ChilkatHttpResponse
resp.Initialize

'  Use the full display name. AddParam encodes spaces and punctuation.
Dim listName As String = "Workshop announcements"
Dim query As ChilkatHttpRequest
query.Initialize
query.HttpVerb = "GET"
query.AddParam("name", listName)
query.AddParam("status", "active")
query.AddParam("include_membership_count", "active")
success = http.HttpReq("https://api.cc.email/v3/contact_lists", query, resp)
If (success <> True) And (resp.StatusCode <= 0) Then
    Log("Look up list: HTTP request failed.")
    Return
End If

If (success <> True) Or (resp.StatusCode <> 200) Then
    Log("Look up list: HTTP " & resp.StatusCode & " " & resp.BodyStr)
    Return
End If

Dim matches As ChilkatJsonObject
matches.Initialize
success = matches.Load(resp.BodyStr)
If success <> True Then
    Log("Expected a JSON object in the response.")
    Return
End If

If matches.SizeOfArray("lists") = 0 Then
    Log("No active email list named " & listName)
    Return
End If

If (matches.SizeOfArray("lists") <> 1) Or (matches.StringOfEquals("lists[0].name", listName, True) <> True) Then
    Log("Expected one exact list name.")
    Return
End If

Dim listId As String = matches.StringOf("lists[0].list_id")
If listId = "" Then
    Log("Missing list ID.")
    Return
End If

Log(listName & " | List ID: " & listId & " | Mailable contacts: " & matches.IntOf("lists[0].membership_count"))