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

Constant Contact V3: Compare results for sent email activities

See more Constant Contact Examples

Compare one to ten sent primary_email or resend activities with status DONE. Supply activity IDs from your sent newsletters. Campaign IDs identify a different resource. This report requires campaign_data and permission to view campaign metrics.

Each row shows sends, unique opens, unique clicks, bounces and the last metrics refresh. The code matches results by activity ID, keeps the input order, and prints any partial-success errors alongside the available results. A missing result is reported separately from a measured zero.

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

'  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 ids = Server.CreateObject("Chilkat.JsonArray")
success = ids.AddStringAt(-1,"FIRST_SENT_ACTIVITY_ID")
success = ids.AddStringAt(-1,"SECOND_SENT_ACTIVITY_ID")
If ((ids.Size < 1) Or (ids.Size > 10)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Choose one to ten sent activity IDs.") & "</pre>"
    Response.End
End If

set url = Server.CreateObject("Chilkat.StringBuilder")
success = url.Append("https://api.cc.email/v3/reports/stats/email_campaign_activities/")
i = 0
Do While (i < ids.Size)
    If (i > 0) Then
        success = url.Append(",")
    End If

    success = url.Append(ids.StringAt(i))
    i = i + 1
Loop
success = http.HttpNoBody("GET",url.GetAsString(),resp)
If ((success <> 1) And (resp.StatusCode <= 0)) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Read statistics: HTTP request failed.") & "</pre>"
    Response.End
End If

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

set report = Server.CreateObject("Chilkat.JsonObject")
success = report.Load(resp.BodyStr)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( "Expected a JSON object in the response.") & "</pre>"
    Response.End
End If

i = 0
Do While (i < report.SizeOfArray("errors"))
    report.I = i
    Response.Write "<pre>" & Server.HTMLEncode( report.StringOf("errors[i].error_key") & ": " & report.StringOf("errors[i].error_message")) & "</pre>"
    i = i + 1
Loop
Response.Write "<pre>" & Server.HTMLEncode( "Activity ID | Sends | Unique opens | Unique clicks | Bounces | Last refresh") & "</pre>"
set row = Server.CreateObject("Chilkat.JsonObject")
i = 0
Do While (i < ids.Size)
    id = ids.StringAt(i)
    success = report.FindRecord2("results","campaign_activity_id",id,1,row)
    If (success = 1) Then
        '  StringOf preserves a reported zero and leaves an unavailable individual metric blank.
        Response.Write "<pre>" & Server.HTMLEncode( id & " | " & row.StringOf("stats.em_sends") & " | " & row.StringOf("stats.em_opens") & " | " & row.StringOf("stats.em_clicks") _
             & " | " & row.StringOf("stats.em_bounces") & " | " & row.StringOf("last_refresh_time")) & "</pre>"
    Else
        Response.Write "<pre>" & Server.HTMLEncode( id & " | No statistics returned") & "</pre>"
    End If

    i = i + 1
Loop

%>
</body>
</html>