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

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 Lua Downloads

Lua
local chilkat = require("chilkat")

-- Assumes Chilkat is unlocked. See Global Unlock Sample.
local vault = chilkat.Secrets.new()
vault.location = "local_manager"
vault.auto_split = true
local entry = chilkat.JsonObject.new()
entry:update_string("appName", "ConstantContactV3")
entry:update_string("service", "OAuth2")
entry:update_string("username", "my-account")
local tokens = chilkat.JsonObject.new()
local loaded = vault:get_secret_json(entry, tokens)
if not loaded then
    print("Run the desktop authorization example using this account and store.")
    return
end

if tokens:json_type_of("access_token") ~= 1 then
    print("The saved authorization has no access token.")
    return
end

local http = chilkat.Http.new()
http.require_ssl_cert_verify = true
http.auth_token = tokens:string_of("access_token")
local resp = chilkat.HttpResponse.new()

-- Obtain the selected contact ID from the email lookup example.
http:set_url_var("contactId", "CONTACT_ID")
local success = http:http_no_body("DELETE", "https://api.cc.email/v3/contacts/{$contactId}", resp)
if resp.status_code == 404 then
    print("Contact ID not found in this account.")
    return
end

if (not success) or (resp.status_code ~= 204) then
    print("Expected HTTP 204. Received " .. resp.status_code)
    if resp.status_code == 401 then
        print("Refresh the saved access token or authorize again.")
    end

    return
end

print("Contact deleted and list memberships removed.")