The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Trouble Unsubscribing a registrant through the API, DELETE Endpoint?

Highlighted
Member

Trouble Unsubscribing a registrant through the API, DELETE Endpoint?

Folks that opt in through my site are automatically getting added to the appropriate CC list.  But when they opt out, the id of the email is working below but the opt-out URL is not. It says it needs a DELETE endpoint, how do I do that?  I'm guessing my curl call is wrong.

 

Here is the output I'm getting for the code below: http://wcncbracket.com/cc.php

 

echo "id= " . $response->results[0]->id . "<br>";
curl_close($ch);

$url = "https://api.constantcontact.com/v2/contacts/" . $response->results[0]->id . "?api_key=" . $apiKey;

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

Tags (3)
3 REPLIES 3
Highlighted
Moderator

Re: Trouble Unsubscribing a registrant through the API, DELETE Endpoint?

Hello Brian,

Thank you for reaching out to Constant Contact API Developer Support.

When using our V2 API, in order to opt out or unsubscribe a contact, you would make a DELETE call to the specific contact endpoint URL:

https://api.constantcontact.com/v2/contacts/{contactId}


You would append the returned Contact ID to the URL you are using. See this page in our documentation for details:
https://developer.constantcontact.com/docs/contacts-api/contacts-resource.html?method=DELETE

Regards,

David B.
Tier II API Support Engineer

Highlighted
Member

Re: Trouble Unsubscribing a registrant through the API, DELETE Endpoint?

What do you mean by a delete call?  Is that a CURL option?  Here is what I'm doing now, what am I missing?  And that id is working, I've proved that:

 

$url = "https://api.constantcontact.com/v2/contacts/" . $response->results[0]->id . "?api_key=" . $apiKey;

$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

Highlighted
Moderator

Re: Trouble Unsubscribing a registrant through the API, DELETE Endpoint?

In order to unsubscribe a contact, the HTTP method you would use is DELETE. You can do this in CURL by adding the following line to your options:

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');

Then when sent to the URL of the contact ID it will make a DELETE request instead of just a GET request.

 

Regards,

 

David B.
Tier II API Support Engineer

 

Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured