Removing a Contact from a list

SOLVED
Go to solution
Regular Participant

Removing a Contact from a list

If someone requests to be removed - and doesn't use the CC url - we remove them from our local database,

but when I tried to update the contact record using the API (by $contact->lists = Array( new stdClass());)

when I get the JSON status return - it shows the lists node as blank. However, when I reread the contact

using a new API call - the lists node change is not saved.

 

Our second step to this would be to update the $contact->status from ACTIVE to REMOVED but that's another project!

 

How do I remove a listid from a contact using the API?

 

Thanks

1 ACCEPTED SOLUTION

There's two ways to look at deleting a contact:

  1. Remove the contact from all lists and hide the contact in the UI (This is a soft delete, the same as the delete option in the UI)
  2. Unsubscribe/opt-out.

 

For option 1, you need to send an update for the contact where the contact is assigned to no lists. If you're calling the API directly, it would be as follows:

  1. Get the contact details: GET https://api.constantcontact.com/v2/contacts/{contactId}
  2. Take the contact object returned by the above call and override the lists array with a blank array: $contact->lists = array();
  3. Send an update to the contact: PUT https://api.constantcontact.com/v2/contacts/{contactId}
      Send the JSON for the updated contact as the request body

For option 2, you simply need to make the following call:

 

You can find documentation for this endpoint and each of the three actions here: 

http://developer.constantcontact.com/docs/contacts-api/contacts-resource.html

 

If you don't know the contact ID, you can search for it using the "email" query parameter on this endpoint:

http://developer.constantcontact.com/docs/contacts-api/contacts-collection.html

 

If you have any questions, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer

View solution in original post

3 REPLIES 3
Member

Hello,

 

You're definitely on the right track for how to remove a contact from a list!

 

The proper method for this is as follows:

Get the current contact details from Constant Contact:

$contact = $contactServiceObject.getContact($accessToken, $contactId);

Update the contact and remove list(s): 

// To remove all lists, simply use $contact->lists = array();
foreach ($contact->lists as $key => $value) { if ($value->name == "List Name") { // You can also match list ID instead of name unset($contact->lists[$key]); } }

Send the updated contact info to Constant Contact:

$contactServiceObject.updateContact($accessToken, $contact);

The above steps are built around the current version of our PHP SDK. It is also worth noting that the $contact->status field is read-only on the API and it is inferred based on the contact's list memberships and/or optout status. If a contact wishes to opt-out from all future mailings, then the proper approach is to use the deleteContact() method of the ContactService object.

 

If you have any questions, please let me know!

 

Sincerely,

 

Elijah G.
API Support Engineer

Thanks.

 

I've looked into the docs and can not seem to find how to delete a contact - It appears (looking at the API testing page) as if it's the same as retrieving a contact based on url displayed, using the contactid. but that can't be the case - how does the API distinguish between a retrieval and a delete? Is it solely based on a GET request vs a PUT/POST request?

 

I'm not using the SDK - I am having issues getting it to function, which I'm attributing to I'm using it from the Command Line and not from a webserever request.

 

What would be the API URL ?

 

 

There's two ways to look at deleting a contact:

  1. Remove the contact from all lists and hide the contact in the UI (This is a soft delete, the same as the delete option in the UI)
  2. Unsubscribe/opt-out.

 

For option 1, you need to send an update for the contact where the contact is assigned to no lists. If you're calling the API directly, it would be as follows:

  1. Get the contact details: GET https://api.constantcontact.com/v2/contacts/{contactId}
  2. Take the contact object returned by the above call and override the lists array with a blank array: $contact->lists = array();
  3. Send an update to the contact: PUT https://api.constantcontact.com/v2/contacts/{contactId}
      Send the JSON for the updated contact as the request body

For option 2, you simply need to make the following call:

 

You can find documentation for this endpoint and each of the three actions here: 

http://developer.constantcontact.com/docs/contacts-api/contacts-resource.html

 

If you don't know the contact ID, you can search for it using the "email" query parameter on this endpoint:

http://developer.constantcontact.com/docs/contacts-api/contacts-collection.html

 

If you have any questions, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer

View solution in original post

Developer Portal

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

Visit Page