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

Xbase++
LOCAL nSuccess
LOCAL oVault
LOCAL oEntry
LOCAL oTokens
LOCAL nLoaded
LOCAL oHttp
LOCAL oResp

nSuccess := 0

//  Assumes Chilkat is unlocked. See Global Unlock Sample.
oVault := CreateObject("Chilkat.Secrets")
oVault:Location := "local_manager"
oVault:AutoSplit := 1
oEntry := CreateObject("Chilkat.JsonObject")
oEntry:UpdateString("appName", "ConstantContactV3")
oEntry:UpdateString("service", "OAuth2")
oEntry:UpdateString("username", "my-account")
oTokens := CreateObject("Chilkat.JsonObject")
nLoaded := oVault:GetSecretJson(oEntry, oTokens)
IF (nLoaded != 1)
    ? "Run the desktop authorization example using this account and store."
    oVault:destroy()
    oEntry:destroy()
    oTokens:destroy()
    RETURN
ENDIF

IF (oTokens:JsonTypeOf("access_token") != 1)
    ? "The saved authorization has no access token."
    oVault:destroy()
    oEntry:destroy()
    oTokens:destroy()
    RETURN
ENDIF

oHttp := CreateObject("Chilkat.Http")
oHttp:RequireSslCertVerify := 1
oHttp:AuthToken := oTokens:StringOf("access_token")
oResp := CreateObject("Chilkat.HttpResponse")

//  Obtain the selected contact ID from the email lookup example.
oHttp:SetUrlVar("contactId", "CONTACT_ID")
nSuccess := oHttp:HttpNoBody("DELETE", "https://api.cc.email/v3/contacts/{$contactId}", oResp)
IF (oResp:StatusCode == 404)
    ? "Contact ID not found in this account."
    oVault:destroy()
    oEntry:destroy()
    oTokens:destroy()
    oHttp:destroy()
    oResp:destroy()
    RETURN
ENDIF

IF ((nSuccess != 1) .OR. (oResp:StatusCode != 204))
    ? "Expected HTTP 204. Received " + Str(oResp:StatusCode)
    IF (oResp:StatusCode == 401)
        ? "Refresh the saved access token or authorize again."
    ENDIF

    oVault:destroy()
    oEntry:destroy()
    oTokens:destroy()
    oHttp:destroy()
    oResp:destroy()
    RETURN
ENDIF

? "Contact deleted and list memberships removed."

oVault:destroy()
oEntry:destroy()
oTokens:destroy()
oHttp:destroy()
oResp:destroy()