Visual Basic 6.0 Requires Chilkat v11.0.0+
Visual Basic 6.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 Visual Basic 6.0 Downloads
Dim success As Long
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim vault As New ChilkatSecrets
vault.Location = "local_manager"
vault.AutoSplit = 1
Dim entry As New ChilkatJsonObject
success = entry.UpdateString("appName","ConstantContactV3")
success = entry.UpdateString("service","OAuth2")
success = entry.UpdateString("username","my-account")
Dim tokens As New ChilkatJsonObject
Dim loaded As Long
loaded = vault.GetSecretJson(entry,tokens)
If (loaded <> 1) Then
Debug.Print "Run the desktop authorization example using this account and store."
Exit Sub
End If
If (tokens.JsonTypeOf("access_token") <> 1) Then
Debug.Print "The saved authorization has no access token."
Exit Sub
End If
Dim http As New ChilkatHttp
http.RequireSslCertVerify = 1
http.AuthToken = tokens.StringOf("access_token")
Dim resp As New ChilkatHttpResponse
' Use the full display name. AddParam encodes spaces and punctuation.
Dim listName As String
listName = "Workshop announcements"
Dim query As New ChilkatHttpRequest
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 <> 1) And (resp.StatusCode <= 0)) Then
Debug.Print "Look up list: HTTP request failed."
Exit Sub
End If
If ((success <> 1) Or (resp.StatusCode <> 200)) Then
Debug.Print "Look up list: HTTP " & resp.StatusCode & " " & resp.BodyStr
Exit Sub
End If
Dim matches As New ChilkatJsonObject
success = matches.Load(resp.BodyStr)
If (success <> 1) Then
Debug.Print "Expected a JSON object in the response."
Exit Sub
End If
If (matches.SizeOfArray("lists") = 0) Then
Debug.Print "No active email list named " & listName
Exit Sub
End If
If ((matches.SizeOfArray("lists") <> 1) Or (matches.StringOfEquals("lists[0].name",listName,1) <> 1)) Then
Debug.Print "Expected one exact list name."
Exit Sub
End If
Dim listId As String
listId = matches.StringOf("lists[0].list_id")
If (listId = "") Then
Debug.Print "Missing list ID."
Exit Sub
End If
Debug.Print listName & " | List ID: " & listId & " | Mailable contacts: " & matches.IntOf("lists[0].membership_count")