Classic ASP Requires Chilkat v11.0.0+
Classic ASP
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 Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
' Assumes Chilkat is unlocked. See Global Unlock Sample.
set vault = Server.CreateObject("Chilkat.Secrets")
vault.Location = "local_manager"
vault.AutoSplit = 1
set entry = Server.CreateObject("Chilkat.JsonObject")
success = entry.UpdateString("appName","ConstantContactV3")
success = entry.UpdateString("service","OAuth2")
success = entry.UpdateString("username","my-account")
set tokens = Server.CreateObject("Chilkat.JsonObject")
loaded = vault.GetSecretJson(entry,tokens)
If (loaded <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Run the desktop authorization example using this account and store.") & "</pre>"
Response.End
End If
If (tokens.JsonTypeOf("access_token") <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "The saved authorization has no access token.") & "</pre>"
Response.End
End If
set http = Server.CreateObject("Chilkat.Http")
http.RequireSslCertVerify = 1
http.AuthToken = tokens.StringOf("access_token")
set resp = Server.CreateObject("Chilkat.HttpResponse")
' Use the full display name. AddParam encodes spaces and punctuation.
listName = "Workshop announcements"
set query = Server.CreateObject("Chilkat.HttpRequest")
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
Response.Write "<pre>" & Server.HTMLEncode( "Look up list: HTTP request failed.") & "</pre>"
Response.End
End If
If ((success <> 1) Or (resp.StatusCode <> 200)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Look up list: HTTP " & resp.StatusCode & " " & resp.BodyStr) & "</pre>"
Response.End
End If
set matches = Server.CreateObject("Chilkat.JsonObject")
success = matches.Load(resp.BodyStr)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Expected a JSON object in the response.") & "</pre>"
Response.End
End If
If (matches.SizeOfArray("lists") = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( "No active email list named " & listName) & "</pre>"
Response.End
End If
If ((matches.SizeOfArray("lists") <> 1) Or (matches.StringOfEquals("lists[0].name",listName,1) <> 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Expected one exact list name.") & "</pre>"
Response.End
End If
listId = matches.StringOf("lists[0].list_id")
If (listId = "") Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing list ID.") & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( listName & " | List ID: " & listId & " | Mailable contacts: " & matches.IntOf("lists[0].membership_count")) & "</pre>"
%>
</body>
</html>