PowerShell Requires Chilkat v11.0.0+
PowerShell
Constant Contact V3: Delete a contact by ID
See more Constant Contact Examples
Use the ID of the contact selected for deletion. Deletion removes all list memberships and sets the deletion timestamp. Unsubscribing is a separate operation that changes permission to send. A successful delete returns HTTP 204 with an empty body. To bring the record back, see Restore a deleted contact. Authorize the app first and use the same credential store.
Constant Contact developer guide
Chilkat PowerShell Downloads
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
# Obtain the selected contact ID from the email lookup example.
$http.SetUrlVar("contactId","CONTACT_ID")
$success = $http.HttpNoBody("DELETE","https://api.cc.email/v3/contacts/{$contactId}",$resp)
if ($resp.StatusCode -eq 404) {
$("Contact ID not found in this account.")
exit
}
if (($success -ne $true) -or ($resp.StatusCode -ne 204)) {
$("Expected HTTP 204. Received " + $resp.StatusCode)
if ($resp.StatusCode -eq 401) {
$("Refresh the saved access token or authorize again.")
}
exit
}
$("Contact deleted and list memberships removed.")