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

Constant Contact V3: Create a contact list

See more Constant Contact Examples

Create a list with a unique name and a short description. Save the returned list_id with your application’s list record and use it in the membership examples. The new list starts empty. Authorize the app first and use the same 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

$body = New-Object Chilkat.JsonObject
$body.UpdateString("name","Workshop announcements")
$body.UpdateString("description","People who requested workshop updates")
$success = $http.HttpJson("POST","https://api.cc.email/v3/contact_lists",$body,"application/json",$resp)
if ($resp.StatusCode -eq 409) {
    $("A conflicting list already exists. Check the existing lists before retrying.")
    exit
}

if (($success -ne $true) -or ($resp.StatusCode -ne 201)) {
    $("Expected HTTP 201. Received " + $resp.StatusCode)
    if ($resp.StatusCode -eq 401) {
        $("Refresh the saved access token or authorize again.")
    }

    exit
}

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

if (($created.JsonTypeOf("list_id") -ne 1) -or ($created.StringOfEquals("list_id","",$true) -eq $true)) {
    $("Missing list_id in the response.")
    exit
}

$("Created " + $created.StringOf("name") + ". List ID: " + $created.StringOf("list_id"))