Sample code for 30+ languages & platforms
AutoIt 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 AutoIt Downloads

AutoIt
Local $bSuccess = False

;  Assumes Chilkat is unlocked. See Global Unlock Sample.
$oVault = ObjCreate("Chilkat.Secrets")
$oVault.Location = "local_manager"
$oVault.AutoSplit = True
$oEntry = ObjCreate("Chilkat.JsonObject")
$oEntry.UpdateString("appName","ConstantContactV3")
$oEntry.UpdateString("service","OAuth2")
$oEntry.UpdateString("username","my-account")
$oTokens = ObjCreate("Chilkat.JsonObject")
Local $bLoaded = $oVault.GetSecretJson($oEntry,$oTokens)
If ($bLoaded <> True) Then
    ConsoleWrite("Run the desktop authorization example using this account and store." & @CRLF)
    Exit
EndIf

If ($oTokens.JsonTypeOf("access_token") <> 1) Then
    ConsoleWrite("The saved authorization has no access token." & @CRLF)
    Exit
EndIf

$oHttp = ObjCreate("Chilkat.Http")
$oHttp.RequireSslCertVerify = True
$oHttp.AuthToken = $oTokens.StringOf("access_token")
$oResp = ObjCreate("Chilkat.HttpResponse")

$oIds = ObjCreate("Chilkat.JsonArray")
$oIds.AddStringAt(-1,"FIRST_SENT_ACTIVITY_ID")
$oIds.AddStringAt(-1,"SECOND_SENT_ACTIVITY_ID")
If (($oIds.Size < 1) Or ($oIds.Size > 10)) Then
    ConsoleWrite("Choose one to ten sent activity IDs." & @CRLF)
    Exit
EndIf

$oUrl = ObjCreate("Chilkat.StringBuilder")
$oUrl.Append("https://api.cc.email/v3/reports/stats/email_campaign_activities/")
Local $i = 0
While ($i < $oIds.Size)
    If ($i > 0) Then
        $oUrl.Append(",")
    EndIf

    $oUrl.Append($oIds.StringAt($i))
    $i = $i + 1
Wend
$bSuccess = $oHttp.HttpNoBody("GET",$oUrl.GetAsString(),$oResp)
If (($bSuccess <> True) And ($oResp.StatusCode <= 0)) Then
    ConsoleWrite("Read statistics: HTTP request failed." & @CRLF)
    Exit
EndIf

If (($bSuccess <> True) Or (($oResp.StatusCode < 200) Or ($oResp.StatusCode >= 300))) Then
    ConsoleWrite("Read statistics: HTTP " & $oResp.StatusCode & " " & $oResp.BodyStr & @CRLF)
    Exit
EndIf

$oReport = ObjCreate("Chilkat.JsonObject")
$bSuccess = $oReport.Load($oResp.BodyStr)
If ($bSuccess <> True) Then
    ConsoleWrite("Expected a JSON object in the response." & @CRLF)
    Exit
EndIf

$i = 0
While ($i < $oReport.SizeOfArray("errors"))
    $oReport.I = $i
    ConsoleWrite($oReport.StringOf("errors[i].error_key") & ": " & $oReport.StringOf("errors[i].error_message") & @CRLF)
    $i = $i + 1
Wend
ConsoleWrite("Activity ID | Sends | Unique opens | Unique clicks | Bounces | Last refresh" & @CRLF)
$oRow = ObjCreate("Chilkat.JsonObject")
$i = 0
While ($i < $oIds.Size)
Local $sId = $oIds.StringAt($i)
    $bSuccess = $oReport.FindRecord2("results","campaign_activity_id",$sId,True,$oRow)
    If ($bSuccess = True) Then
        ;  StringOf preserves a reported zero and leaves an unavailable individual metric blank.
        ConsoleWrite($sId & " | " & $oRow.StringOf("stats.em_sends") & " | " & $oRow.StringOf("stats.em_opens") & " | " & $oRow.StringOf("stats.em_clicks") & " | " _
             & $oRow.StringOf("stats.em_bounces") & " | " & $oRow.StringOf("last_refresh_time") & @CRLF)
    Else
        ConsoleWrite($sId & " | No statistics returned" & @CRLF)
    EndIf

    $i = $i + 1
Wend