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

Swift

func chilkatTest() {
    var success: Bool = false

    //  Assumes Chilkat is unlocked. See Global Unlock Sample.
    let vault = CkoSecrets()!
    vault.location = "local_manager"
    vault.autoSplit = true
    let entry = CkoJsonObject()!
    entry.updateString(jsonPath: "appName", value: "ConstantContactV3")
    entry.updateString(jsonPath: "service", value: "OAuth2")
    entry.updateString(jsonPath: "username", value: "my-account")
    let tokens = CkoJsonObject()!
    var loaded: Bool = vault.getSecretJson(jsonId: entry, jsonOut: tokens)
    if loaded != true {
        print("Run the desktop authorization example using this account and store.")
        return
    }

    if tokens.jsonType(of: "access_token").intValue != 1 {
        print("The saved authorization has no access token.")
        return
    }

    let http = CkoHttp()!
    http.requireSslCertVerify = true
    http.authToken = tokens.string(of: "access_token")
    let resp = CkoHttpResponse()!

    //  Obtain the selected contact ID from the email lookup example.
    http.setUrlVar(name: "contactId", value: "CONTACT_ID")
    success = http.httpNoBody(verb: "DELETE", url: "https://api.cc.email/v3/contacts/{$contactId}", response: resp)
    if resp.statusCode.intValue == 404 {
        print("Contact ID not found in this account.")
        return
    }

    if (success != true) || (resp.statusCode.intValue != 204) {
        print("Expected HTTP 204. Received \(resp.statusCode.intValue)")
        if resp.statusCode.intValue == 401 {
            print("Refresh the saved access token or authorize again.")
        }

        return
    }

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

}