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

SQL Server
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    --  Assumes Chilkat is unlocked. See Global Unlock Sample.
    DECLARE @vault int
    EXEC @hr = sp_OACreate 'Chilkat.Secrets', @vault OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OASetProperty @vault, 'Location', 'local_manager'
    EXEC sp_OASetProperty @vault, 'AutoSplit', 1
    DECLARE @entry int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @entry OUT

    EXEC sp_OAMethod @entry, 'UpdateString', @success OUT, 'appName', 'ConstantContactV3'
    EXEC sp_OAMethod @entry, 'UpdateString', @success OUT, 'service', 'OAuth2'
    EXEC sp_OAMethod @entry, 'UpdateString', @success OUT, 'username', 'my-account'
    DECLARE @tokens int
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @tokens OUT

    DECLARE @loaded int
    EXEC sp_OAMethod @vault, 'GetSecretJson', @loaded OUT, @entry, @tokens
    IF @loaded <> 1
      BEGIN

        PRINT 'Run the desktop authorization example using this account and store.'
        EXEC @hr = sp_OADestroy @vault
        EXEC @hr = sp_OADestroy @entry
        EXEC @hr = sp_OADestroy @tokens
        RETURN
      END
    EXEC sp_OAMethod @tokens, 'JsonTypeOf', @iTmp0 OUT, 'access_token'
    IF @iTmp0 <> 1
      BEGIN

        PRINT 'The saved authorization has no access token.'
        EXEC @hr = sp_OADestroy @vault
        EXEC @hr = sp_OADestroy @entry
        EXEC @hr = sp_OADestroy @tokens
        RETURN
      END
    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT

    EXEC sp_OASetProperty @http, 'RequireSslCertVerify', 1
    EXEC sp_OAMethod @tokens, 'StringOf', @sTmp0 OUT, 'access_token'
    EXEC sp_OASetProperty @http, 'AuthToken', @sTmp0
    DECLARE @resp int
    EXEC @hr = sp_OACreate 'Chilkat.HttpResponse', @resp OUT

    --  Obtain the selected contact ID from the email lookup example.
    EXEC sp_OAMethod @http, 'SetUrlVar', @success OUT, 'contactId', 'CONTACT_ID'
    EXEC sp_OAMethod @http, 'HttpNoBody', @success OUT, 'DELETE', 'https://api.cc.email/v3/contacts/{$contactId}', @resp
    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    IF @iTmp0 = 404
      BEGIN

        PRINT 'Contact ID not found in this account.'
        EXEC @hr = sp_OADestroy @vault
        EXEC @hr = sp_OADestroy @entry
        EXEC @hr = sp_OADestroy @tokens
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @resp
        RETURN
      END
    EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
    IF (@success <> 1) or (@iTmp0 <> 204)
      BEGIN

        EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
        PRINT 'Expected HTTP 204. Received ' + @iTmp0
        EXEC sp_OAGetProperty @resp, 'StatusCode', @iTmp0 OUT
        IF @iTmp0 = 401
          BEGIN

            PRINT 'Refresh the saved access token or authorize again.'
          END
        EXEC @hr = sp_OADestroy @vault
        EXEC @hr = sp_OADestroy @entry
        EXEC @hr = sp_OADestroy @tokens
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @resp
        RETURN
      END

    PRINT 'Contact deleted and list memberships removed.'

    EXEC @hr = sp_OADestroy @vault
    EXEC @hr = sp_OADestroy @entry
    EXEC @hr = sp_OADestroy @tokens
    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @resp


END
GO