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

Constant Contact V3: Find a contact list by name

See more Constant Contact Examples

Start with the full list name from the Constant Contact account. Read its list_id and the number of active, mailable contacts. Use the ID for list membership operations or campaign targeting. This lookup requires contact_data.

Authorize the application using the same account and credential store.

Constant Contact developer guide

Chilkat PowerShell Downloads

PowerShell
Add-Type -Path "C:\chilkat\ChilkatDotNet47-x64\ChilkatDotNet47.dll"

$success = $false

#  Assumes Chilkat is unlocked. See Global Unlock Sample.
$vault = New-Object Chilkat.Secrets
$vault.Location = "local_manager"
$vault.AutoSplit = $true
$entry = New-Object Chilkat.JsonObject
$entry.UpdateString("appName","ConstantContactV3")
$entry.UpdateString("service","OAuth2")
$entry.UpdateString("username","my-account")
$tokens = New-Object Chilkat.JsonObject
$loaded = $vault.GetSecretJson($entry,$tokens)
if ($loaded -ne $true) {
    $("Run the desktop authorization example using this account and store.")
    exit
}

if ($tokens.JsonTypeOf("access_token") -ne 1) {
    $("The saved authorization has no access token.")
    exit
}

$http = New-Object Chilkat.Http
$http.RequireSslCertVerify = $true
$http.AuthToken = $tokens.StringOf("access_token")
$resp = New-Object Chilkat.HttpResponse

#  Use the full display name. AddParam encodes spaces and punctuation.
$listName = "Workshop announcements"
$query = New-Object 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 -ne $true) -and ($resp.StatusCode -le 0)) {
    $("Look up list: HTTP request failed.")
    exit
}

if (($success -ne $true) -or ($resp.StatusCode -ne 200)) {
    $("Look up list: HTTP " + $resp.StatusCode + " " + $resp.BodyStr)
    exit
}

$matches = New-Object Chilkat.JsonObject
$success = $matches.Load($resp.BodyStr)
if ($success -ne $true) {
    $("Expected a JSON object in the response.")
    exit
}

if ($matches.SizeOfArray("lists") -eq 0) {
    $("No active email list named " + $listName)
    exit
}

if (($matches.SizeOfArray("lists") -ne 1) -or ($matches.StringOfEquals("lists[0].name",$listName,$true) -ne $true)) {
    $("Expected one exact list name.")
    exit
}

$listId = $matches.StringOf("lists[0].list_id")
if ($listId -eq "") {
    $("Missing list ID.")
    exit
}

$($listName + " | List ID: " + $listId + " | Mailable contacts: " + $matches.IntOf("lists[0].membership_count"))