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.

500 Internal Server Error

Highlighted
Occasional Participant

500 Internal Server Error

Please post a sample code to update a contact email to another list.


public function updateContactList($email,$c_id) {

           

            $id = "http://api.constantcontact.com/ws/customers/USERNAME/contacts/$c_id";



            $entry = '<entry xmlns="http://www.w3.org/2005/Atom">

                      <id>http://api.constantcontact.com/ws/customers/'.$this->login.'/contacts/'.$c_id.'</id>

                      <title type="text">Contact: '.$email.'</title>

                      <updated>'.date("Y-m-d").'T'.date("H:i:s").'+01:00'.'</updated>

                      <author><name>Mahesh Kumar</name></author>

                      <content type="application/vnd.ctct+xml">

                      <Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/'.$this->login.'/contacts/'.$c_id.'">

                          <EmailAddress>'.$email.'</EmailAddress>

                          <OptInSource>ACTION_BY_CUSTOMER</OptInSource>

                          <ContactLists>

                            <ContactList id="http://api.constantcontact.com/ws/customers/'.$this->login.'/lists/1">

                            </ContactList>

                          </ContactLists>

                        </Contact>

                      </content>

                    </entry>';



           

            $request ="http://api.constantcontact.com/ws/customers/".$this->login."/contacts/".$c_id;

            $this->doServerCall($request, $entry, 'PUT');

    }


 


I am getting 500 Internal Server Error.

Please really develope your API docs. For a simple xml request i need to ask your help or i have to choose a developer

1 REPLY 1
Highlighted
Employee

Re: 500 Internal Server Error

I apologize for any inconvenience that this has caused. Unfortunately, I was not able to replicate the 500 error that you were experiencing. I was able to take the function you pasted, and use it in the CC_Contact Class to successfully update a contact. The code I used to call this function was:


 


$CC = new CC_Contact();

$updateContact = $CC->updateContactList($email, $c_id);


 


The entire CC_Contact class I used is pasted below. I would like to let you know that this function is going to update everyone to be a part of list id 1, which is the 'General Interest' list by default. If you are looking to modify the lists that a contact is subscribed to, the recommended method would be:


 


1. Perform a GET on that contact (https://api.constantcontact.com/ws/customers/{user-name}/contacts/{contact-id}


2. Update the <ContactLists> element of their XML to include only the <ContactList> elements for the lists that you wish them to be subscribed to. I would recommend taking a look at Adding or Removing a Contact from a List for more information on this process.


3. Perform an http PUT to that contact ID's URL to update the contact. This will subscribe that contact to ONLY the lists specified in the XML that you are passing in your request body. The contact will be removed from any lists that are not included in the XML.


 


The CC_Contact class is below


 


           class CC_Contact extends CC_Utility {

   

    public function updateContactList($email,$c_id) {

           $id = "http://api.constantcontact.com/ws/customers/USERNAME/contacts/$c_id";



        $entry = '<entry xmlns="http://www.w3.org/2005/Atom">

                  <id>http://api.constantcontact.com/ws/customers/'.$this->login.'/contacts/'.$c_id.'</id>

                  <title type="text">Contact: '.$email.'</title>

                  <updated>'.date("Y-m-d").'T'.date("H:i:s").'+01:00'.'</updated>

                  <author><name>Mahesh Kumar</name></author>

                  <content type="application/vnd.ctct+xml">

                  <Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/'.$this->login.'/contacts/'.$c_id.'">

                      <EmailAddress>'.$email.'</EmailAddress>

                      <OptInSource>ACTION_BY_CUSTOMER</OptInSource>

                      <ContactLists>

                        <ContactList id="http://api.constantcontact.com/ws/customers/'.$this->login.'/lists/1">

                        </ContactList>

                      </ContactLists>

                    </Contact>

                  </content>

                </entry>';





        $request ="https://api.constantcontact.com/ws/customers/".$this->login."/contacts/".$c_id;

        $this->doServerCall($request, $entry, 'PUT');

       

}



}

David J

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