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

Constant Contact V3: LIVE SEND - Schedule a newsletter for a named list

See more Constant Contact Examples

LIVE SEND. Scheduling this campaign delivers email to eligible contacts on the selected list at the specified time. Use the reviewer test to check the email first. Select the intended newsletter and list in the same account. The example accepts a primary draft, replaces its entire audience with one active email list, and schedules it. List lookup requires contact_data. Editing and scheduling require campaign_data and account privileges to edit and send.

Enter a future ISO 8601 timestamp with a UTC offset or Z. To cancel before delivery starts, keep the same activity selection, change action to unschedule, and run again. Cancellation removes the schedule and keeps the audience assignment. If the scheduling response is lost, check the activity’s schedule before retrying.

Authorize the application using the same account and credential store.

Constant Contact developer guide

Chilkat Classic ASP Downloads

Classic ASP
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0

'  LIVE SEND: Scheduling this activity delivers email to the selected contact list.
'  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 selection file from the draft or campaign lookup example for this account.
set selection = Server.CreateObject("Chilkat.JsonObject")
success = selection.LoadFile("newsletter-selection.json")
activityId = selection.StringOf("campaign_activity_id")
If ((success <> 1) Or (activityId = "")) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Select a campaign and save its primary activity ID first.") & "</pre>"
    Response.End
End If

success = http.SetUrlVar("activity",activityId)
action = "schedule"
If (action = "unschedule") Then
    success = http.HttpNoBody("DELETE","https://api.cc.email/v3/emails/activities/{$activity}/schedules",resp)
    If ((success <> 1) And (resp.StatusCode <= 0)) Then
        Response.Write "<pre>" & Server.HTMLEncode( "Remove schedule: HTTP request failed.") & "</pre>"
        Response.End
    End If

    If ((success <> 1) Or (resp.StatusCode <> 204)) Then
        Response.Write "<pre>" & Server.HTMLEncode( "Remove schedule: HTTP " & resp.StatusCode & " " & resp.BodyStr) & "</pre>"
        Response.End
    End If

    Response.Write "<pre>" & Server.HTMLEncode( "Schedule removed for activity " & activityId) & "</pre>"
    Response.End
End If

If (action <> "schedule") Then
    Response.Write "<pre>" & Server.HTMLEncode( "Choose schedule or unschedule.") & "</pre>"
    Response.End
End If

'  Replace the placeholder with the intended future delivery time, e.g. 2030-05-15T09:00:00-05:00.
deliveryTime = "ENTER_FUTURE_TIMESTAMP_WITH_OFFSET"
set delivery = Server.CreateObject("Chilkat.CkDateTime")
set now = Server.CreateObject("Chilkat.CkDateTime")
success = now.SetFromCurrentSystemTime()
success = delivery.SetFromTimestamp(deliveryTime)
If ((success <> 1) Or (delivery.DiffSeconds(now) <= 0)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Enter a valid future delivery time with a UTC offset or Z.") & "</pre>"
    Response.End
End If

'  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>"

'  PUT replaces the activity. Read it first to preserve the subject, sender and other settings.
'  Constant Contact retains omitted subresources such as html_content and the physical footer.
success = http.HttpNoBody("GET","https://api.cc.email/v3/emails/activities/{$activity}",resp)
If ((success <> 1) And (resp.StatusCode <= 0)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Read draft: HTTP request failed.") & "</pre>"
    Response.End
End If

If ((success <> 1) Or (resp.StatusCode <> 200)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Read draft: HTTP " & resp.StatusCode & " " & resp.BodyStr) & "</pre>"
    Response.End
End If

set draft = Server.CreateObject("Chilkat.JsonObject")
success = draft.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 ((draft.StringOfEquals("role","primary_email",1) <> 1) Or (draft.StringOfEquals("current_status","DRAFT",1) <> 1)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Select a primary activity in DRAFT status.") & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "LIVE SEND: " & draft.StringOf("subject") & " | Activity: " & activityId & " | List: " & listName & " | Delivery: " & deliveryTime) & "</pre>"
success = draft.UpdateNewArray("contact_list_ids")
success = draft.UpdateString("contact_list_ids[0]",listId)
success = draft.UpdateNewArray("segment_ids")
success = http.HttpJson("PUT","https://api.cc.email/v3/emails/activities/{$activity}",draft,"application/json",resp)
If ((success <> 1) And (resp.StatusCode <= 0)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Assign audience: HTTP request failed.") & "</pre>"
    Response.End
End If

If ((success <> 1) Or (resp.StatusCode <> 200)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Assign audience: HTTP " & resp.StatusCode & " " & resp.BodyStr) & "</pre>"
    Response.End
End If

set updated = Server.CreateObject("Chilkat.JsonObject")
success = updated.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 ((updated.SizeOfArray("contact_list_ids") <> 1) Or (updated.StringOfEquals("contact_list_ids[0]",listId,1) <> 1) Or (updated.SizeOfArray("segment_ids") > 0)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "The saved audience did not match the requested list. Scheduling stopped.") & "</pre>"
    Response.End
End If

set schedule = Server.CreateObject("Chilkat.JsonObject")
success = schedule.UpdateString("scheduled_date",delivery.GetAsTimestamp(0))
success = http.HttpJson("POST","https://api.cc.email/v3/emails/activities/{$activity}/schedules",schedule,"application/json",resp)
If ((success <> 1) Or (resp.StatusCode < 200) Or (resp.StatusCode >= 300)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Schedule not confirmed. HTTP " & resp.StatusCode) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( "The audience was saved. Check the schedule before retrying.") & "</pre>"
    Response.End
End If

Response.Write "<pre>" & Server.HTMLEncode( "Live delivery scheduled for " & schedule.StringOf("scheduled_date") & " to " & listName) & "</pre>"

%>
</body>
</html>