Classic ASP Requires Chilkat v11.0.0+
Classic ASP
Constant Contact V3: Restore a deleted contact to a list
See more Constant Contact Examples
Look up the deleted contact by email, then restore it by adding its existing ID to a chosen list. Constant Contact documents this membership activity as a restoration method. It changes only membership, preserves the saved profile, and makes no email-permission claim. Select the intended destination list explicitly; previous memberships were removed by deletion. Authorize the app first and use the same 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")
set query = Server.CreateObject("Chilkat.HttpRequest")
query.HttpVerb = "GET"
query.AddParam "email","reader+newsletter@example.com"
query.AddParam "status","deleted"
success = http.HttpReq("https://api.cc.email/v3/contacts",query,resp)
If ((success <> 1) Or (resp.StatusCode <> 200)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Expected HTTP 200. Received " & resp.StatusCode) & "</pre>"
If (resp.StatusCode = 401) Then
Response.Write "<pre>" & Server.HTMLEncode( "Refresh the saved access token or authorize again.") & "</pre>"
End If
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 response.") & "</pre>"
Response.End
End If
If ((matches.SizeOfArray("contacts") <> 1) Or (matches.JsonTypeOf("contacts[0].deleted_at") <> 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Expected one deleted contact for this email. No restoration submitted.") & "</pre>"
Response.End
End If
If ((matches.JsonTypeOf("contacts[0].contact_id") <> 1) Or (matches.StringOfEquals("contacts[0].contact_id","",1) = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing contacts[0].contact_id in the response.") & "</pre>"
Response.End
End If
set body = Server.CreateObject("Chilkat.JsonObject")
success = body.UpdateString("source.contact_ids[0]",matches.StringOf("contacts[0].contact_id"))
success = body.UpdateString("list_ids[0]","DESTINATION_LIST_ID")
success = http.HttpJson("POST","https://api.cc.email/v3/activities/add_list_memberships",body,"application/json",resp)
If ((success <> 1) Or (resp.StatusCode < 200) Or (resp.StatusCode >= 300)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not start the membership activity. HTTP " & resp.StatusCode) & "</pre>"
Response.End
End If
set job = Server.CreateObject("Chilkat.JsonObject")
success = job.Load(resp.BodyStr)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Expected a JSON response.") & "</pre>"
Response.End
End If
If ((job.JsonTypeOf("activity_id") <> 1) Or (job.StringOfEquals("activity_id","",1) = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing activity_id in the response.") & "</pre>"
Response.End
End If
activityId = job.StringOf("activity_id")
Response.Write "<pre>" & Server.HTMLEncode( "Submitted activity ID: " & activityId) & "</pre>"
success = http.SetUrlVar("job",activityId)
' Poll briefly. A longer-running job can be checked later using the same ID.
attempt = 0
Do While (attempt < 5)
success = http.HttpNoBody("GET","https://api.cc.email/v3/activities/{$job}",resp)
If ((success <> 1) Or (resp.StatusCode <> 200)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Status check returned HTTP " & resp.StatusCode & ". Keep the activity ID and check again later.") & "</pre>"
Response.End
End If
success = job.Load(resp.BodyStr)
If ((success <> 1) Or (job.JsonTypeOf("state") <> 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing activity state. Keep the activity ID.") & "</pre>"
Response.End
End If
state = job.StringOf("state")
If ((state <> "initialized") And (state <> "processing")) Then
Response.Write "<pre>" & Server.HTMLEncode( "Activity state: " & state) & "</pre>"
i = 0
Do While (i < job.SizeOfArray("activity_errors"))
job.I = i
Response.Write "<pre>" & Server.HTMLEncode( job.StringOf("activity_errors[i]")) & "</pre>"
i = i + 1
Loop
Response.End
End If
attempt = attempt + 1
If (attempt < 5) Then
http.SleepMs 2000
End If
Loop
Response.Write "<pre>" & Server.HTMLEncode( "Still processing. Recheck the activity ID before submitting another request.") & "</pre>"
%>
</body>
</html>