cancel
Showing results for 
Search instead for 
Did you mean: 

API Help - Copying a Contact to Multiple Lists in PHP

SOLVED
Occasional Participant

API Help - Copying a Contact to Multiple Lists in PHP

We have two forms. Lead Form and Sales Form. We also have a LEAD list and SALES list. 

 

When a lead is captured, it is successfully added to Constant Contact in the our LEAD list. 

 

If the user completes the sales form and our script tries to add to the SALES list via the API, we get an error that the email address already exists. This is because it was added to the LEAD list first. 

 

What is the easiest way to check if contact exists, if it does, then update that contact to be included in the SALES list as well as the LEAD list. Or even remove it from the LEAD list. 

 

Looking for an example in PHP

4 REPLIES
Moderator

Re: API Help - Copying a Contact to Multiple Lists in PHP

Hi @MikeS427,

 

Thank you for reaching out to Constant Contact's API Support.

 

In general you will want to do a GET to see if the contact exists, then do a POST or PUT based on whether it does exist. You can look at our PHP SDK and code samples in our documentation located here.


Regards,
Jimmy D.
Tier II API Support Engineer
Occasional Participant

Re: API Help - Copying a Contact to Multiple Lists in PHP

Are there any PHP examples that don't leverage the SDK? We are on and old version of PHP 5.3 and I think the SDK required 5.4 and above. 

Tags (1)
Moderator

Re: API Help - Copying a Contact to Multiple Lists in PHP

Hello,

The general logic would be the same, you would just need to manually create your API calls using the HTTP request library of your choice. There is a great example of how to make a cURL POST call in PHP to send a JSON payload here: https://stackoverflow.com/a/16920588

So the flow would be to check to see if the contact exists by making a GET to the endpoint https://api.constantcontact.com/v2/contacts passing in the email address as a query parameter.

If the contact does exist all of the information for it will be returned and you can then make a PUT call to the individual contact's endpoint https://api.constantcontact.com/v2/contacts/{contactId} with the updated information.

If the contact does not exist, you can POST to https://api.constantcontact.com/v2/contacts to create the contact.

Please let me know if you have any other questions!

Sincerely,
David B.
Tier II API Support Engineer

Highlighted
Occasional Participant

Re: API Help - Copying a Contact to Multiple Lists in PHP

This worked out perfect, thank you for guiding me in the right direction. 

Still need help?
You can post a new message in the Community or find us on Twitter Mon-Fri 8am - 8pm ET. We've got real people waiting to help you out. Click below to start a conversation!