B4X Requires Chilkat v11.0.0+
B4X
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 B4X Downloads
Dim success As Boolean = False
' Assumes Chilkat is unlocked. See Global Unlock Sample.
Dim vault As ChilkatSecrets
vault.Initialize("vault")
vault.Location = "local_manager"
vault.AutoSplit = True
Dim entry As ChilkatJsonObject
entry.Initialize
entry.UpdateString("appName", "ConstantContactV3")
entry.UpdateString("service", "OAuth2")
entry.UpdateString("username", "my-account")
Dim tokens As ChilkatJsonObject
tokens.Initialize
Dim loaded As Boolean = vault.GetSecretJson(entry, tokens)
If loaded <> True Then
Log("Run the desktop authorization example using this account and store.")
Return
End If
If tokens.JsonTypeOf("access_token") <> 1 Then
Log("The saved authorization has no access token.")
Return
End If
Dim http As ChilkatHttp
http.Initialize("http")
http.RequireSslCertVerify = True
http.AuthToken = tokens.StringOf("access_token")
Dim resp As ChilkatHttpResponse
resp.Initialize
Dim ids As ChilkatJsonArray
ids.Initialize
ids.AddStringAt(-1, "FIRST_SENT_ACTIVITY_ID")
ids.AddStringAt(-1, "SECOND_SENT_ACTIVITY_ID")
If (ids.Size < 1) Or (ids.Size > 10) Then
Log("Choose one to ten sent activity IDs.")
Return
End If
Dim url As ChilkatStringBuilder
url.Initialize
url.Append("https://api.cc.email/v3/reports/stats/email_campaign_activities/")
Dim i As Int = 0
Do While (i < ids.Size)
If i > 0 Then
url.Append(",")
End If
url.Append(ids.StringAt(i))
i = i + 1
Loop
success = http.HttpNoBody("GET", url.GetAsString, resp)
If (success <> True) And (resp.StatusCode <= 0) Then
Log("Read statistics: HTTP request failed.")
Return
End If
If (success <> True) Or ((resp.StatusCode < 200) Or (resp.StatusCode >= 300)) Then
Log("Read statistics: HTTP " & resp.StatusCode & " " & resp.BodyStr)
Return
End If
Dim report As ChilkatJsonObject
report.Initialize
success = report.Load(resp.BodyStr)
If success <> True Then
Log("Expected a JSON object in the response.")
Return
End If
i = 0
Do While (i < report.SizeOfArray("errors"))
report.I = i
Log(report.StringOf("errors[i].error_key") & ": " & report.StringOf("errors[i].error_message"))
i = i + 1
Loop
Log("Activity ID | Sends | Unique opens | Unique clicks | Bounces | Last refresh")
Dim row As ChilkatJsonObject
row.Initialize
i = 0
Do While (i < ids.Size)
Dim id As String = ids.StringAt(i)
success = report.FindRecord2("results", "campaign_activity_id", id, True, row)
If success = True Then
' StringOf preserves a reported zero and leaves an unavailable individual metric blank.
Log(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"))
Else
Log(id & " | No statistics returned")
End If
i = i + 1
Loop