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.

Insert or Update of contact only setting email

Highlighted
Occasional Participant

Insert or Update of contact only setting email

Hi All,


I am using the API and trying to create or update a contact, I can't get the first name and last name values to be accepted.  Is this possible via the API?  If so, anyone have a PHP code sniplet that would help?  Do I need to post any code?


Thank you for your time and help.

5 REPLIES 5
Highlighted
Employee

sample php

Hello,



This is definitely possible in our API. A great example of this working is in our Constant Contact Signup Form generator which you can find here. We also have sample PHP code here that also allows you to add contacts with custom fields.



The Signup form generator requires little to no knowledge of PHP to get running, and gives you the ability to put a form on your site that utilizes the API's with PHP.



If you have any questions please let me know.



Regards,

Benjamin Soder
NOC Analyst
Constant Contact
Highlighted
Occasional Participant

That is pretty much what I am

That is pretty much what I am using.  The classes that is in the second link is what I am using as the wrapper for the API calls.  I am going to post a bit of code below to see if I am doing something incorrectly.


 


$ConstantContact = new CC_Contact();


$postFields = array();


$postFields = $email;


$postFields = $first_name;


$postFields = $last_name;


$contactXML = $ConstantContact->createContactXML(null, $postFields);


$result = $ConstantContact->addSubscriber($contactXML);


 


This is successful. I have also checked the xml and it has the first and last name values set correctly. When I use $ConstantContact->getSubscriberDetails() the only value populated is the email address.


On another note, but similar note, I have to include the following line in order to make it work????


 


$postFields = array('http://api.constantcontact.com/ws/customers/myfootpath/lists/3');


 


Thank you for your time and help, Scot

Highlighted
Employee

Re: That is pretty much what I am

Hi Scot,


The code you are using is correct, and I'm not having any difficulties with it. I've been able to use it to add a contact and successfully return the first and last names that I set. Please be aware that this code will only work for new contacts, and will not work if you are looking to update a contact that already exists within your account. If that is what you are looking to do, you would want to utilize the editSubscriber() function.


Regarding the use of the $postFields array, this is required in order to add a contact to a set of lists in your account. This array is used to populate the <ContactLists> element in the contact XML that is sent in the request body when creating or updating a contact.


If you are still having difficulties adding an email address and including a first and last name, could you please reply to this post with the code that you are using, or include that information in an email to our webservices support team and we'll be happy to take a closer look at it. Thanks.

David J

Highlighted
Occasional Participant

Well I thought I had this

Well I thought I had this working.  I moved this from our dev environment over to our live environment and now when I send a contact the added by field is "site owner"  I retested on the dev server, thinking someone might have changed something over the weekend, and the contact goes in as "contact."  I used a tool to compare the files and they are exactly the same, so now I am at a loss at what could cause this.


Is there some type of listing of urls in which a contact can come from?  That is the only difference: the test and live code sit on different urls.


Please advise.  Thank you.

Highlighted
Employee

action by contact vs action by site owner

Hello,



If you are using the ccclass.php file or the ctct_wrapper.php file, there is an area in the Utility class that allows you to change if you are adding the contact by ACTION_BY_CONTACT or ACTION_BY_CUSTOMER. If you could look at the file on the live server and verify that it is ACTION_BY_CONTACT. If it is, could you please send your code to the webservices support team.



Regards,

Benjamin Soder
NOC Analyst
Constant Contact
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