We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

Trouble Unsubscribing a registrant through the API, DELETE Endpoint?

BrianM5048
Participant

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);

3 REPLIES 3
David_B.
Moderator

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

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);

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