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.

Adding/removing contacts from lists

Highlighted
Member

Adding/removing contacts from lists

Hello, I have been working on a script that allows users to sign up or opt out for our newsletter through our website. I have been able to successfully create contacts but I can't seem to change or remove lists they are subscribed to using the API. I have verified that the lists exist and I am using the PUT method and I do get a valid XML response when I make the request. Here is an example of the xml being sent using the PUT method:

 

 

<?xml version="1.0"  encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
    <id>http://api.constantcontact.com/ws/customers/anonymous/contacts/125973</id>
    <title type="text">Contact: test@test.com</title>
    <updated>2011-11-15T16:48:327Z</updated>
    <author> </author>
    <content type="application/vnd.ctct+xml">
        <Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="https://api.constantcontact.com/ws/customers/anonymous/contacts/125973">
            <EmailAddress>test@test.com</EmailAddress>
            <OptInSource>ACTION_BY_CONTACT</OptInSource>
            <ContactLists>
                <ContactList id="http://api.constantcontact.com/ws/customers/anonymous/lists/1"></ContactList>
            </ContactLists>
        </Contact>
    </content>
</entry>

And here is the reply

 

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <link href="/ws/customers/anonymous/contacts/125973" rel="edit"></link>
  <id>http://api.constantcontact.com/ws/customers/anonymous/contacts/125973</id>
  <title type="text">Contact: test@test.com</title>
  <updated>2011-11-15T20:36:31.000Z</updated>
  <author>
    <name>Constant Contact</name>
  </author>
  <content type="application/vnd.ctct+xml">
    <Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/anonymous/contacts/125973">
      <Status>Active</Status>
      <EmailAddress>test@test.com</EmailAddress>
      <EmailType>HTML</EmailType>
      <Name> </Name>
      <FirstName></FirstName>
      <MiddleName></MiddleName>
      <LastName></LastName>
      <JobTitle></JobTitle>
      <CompanyName></CompanyName>
      <HomePhone></HomePhone>
      <WorkPhone></WorkPhone>
      <Addr1></Addr1>
      <Addr2></Addr2>
      <Addr3></Addr3>
      <City></City>
      <StateCode></StateCode>
      <StateName></StateName>
      <CountryCode></CountryCode>
      <CountryName></CountryName>
      <PostalCode></PostalCode>
      <SubPostalCode></SubPostalCode>
      <Note></Note>
      <CustomField1></CustomField1>
      <CustomField2></CustomField2>
      <CustomField3></CustomField3>
      <CustomField4></CustomField4>
      <CustomField5></CustomField5>
      <CustomField6></CustomField6>
      <CustomField7></CustomField7>
      <CustomField8></CustomField8>
      <CustomField9></CustomField9>
      <CustomField10></CustomField10>
      <CustomField11></CustomField11>
      <CustomField12></CustomField12>
      <CustomField13></CustomField13>
      <CustomField14></CustomField14>
      <CustomField15></CustomField15>
      <ContactLists>
        <ContactList id="http://api.constantcontact.com/ws/customers/anonymous/lists/419">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/anonymous/lists/419" rel="self"></link>
          <OptInSource>ACTION_BY_CUSTOMER</OptInSource>
          <OptInTime>2011-11-15T21:43:29.488Z</OptInTime>
        </ContactList>
      </ContactLists>
      <Confirmed>true</Confirmed>
      <InsertTime>2011-11-15T20:36:31.000Z</InsertTime>
      <LastUpdateTime>2011-11-15T20:36:31.000Z</LastUpdateTime>
    </Contact>
  </content>
  <source>
    <id>http://api.constantcontact.com/ws/customers/anonymous/contacts</id>
    <title type="text">Contacts for Customer: anonymous</title>
    <link href="contacts"></link>
    <link href="contacts" rel="self"></link>
    <author>
      <name>anonymous</name>
    </author>
    <updated>2011-11-15T22:48:33.102Z</updated>
  </source>
</entry>

The response shows that the email is still set to list ID 419 even though I specified an ID of 1 in the request. One thing that has me scratching my head is why the opt-in source says "ACTION_BY_CUSTOMER" when the contact was created using the API with that set to "ACTION_BY_CONTACT".

 

Thx in advance, John

3 REPLIES 3
Highlighted
Employee

Re: Adding/removing contacts from lists

Hey,

 

What if you did a PUT to the colleciton like this:

 

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <link href="/ws/customers/anonymous/contacts/125973" rel="edit"></link>
  <id>http://api.constantcontact.com/ws/customers/anonymous/contacts/125973</id>
  <title type="text">Contact: test@test.com</title>
  <updated>2011-11-15T20:36:31.000Z</updated>
  <author>
    <name>Constant Contact</name>
  </author>
  <content type="application/vnd.ctct+xml">
    <Contact xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/anonymous/contacts/125973">
      <Status>Active</Status>
      <EmailAddress>test@test.com</EmailAddress>
      <EmailType>HTML</EmailType>
      <ContactLists>
        <ContactList id="http://api.constantcontact.com/ws/customers/anonymous/lists/1">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/anonymous/lists/1" rel="self"></link>
          <OptInSource>ACTION_BY_CUSTOMER</OptInSource>
          <OptInTime>2011-11-15T21:43:29.488Z</OptInTime>
        </ContactList>
      </ContactLists>
      <Confirmed>true</Confirmed>
      <InsertTime>2011-11-15T20:36:31.000Z</InsertTime>
      <LastUpdateTime>2011-11-15T20:36:31.000Z</LastUpdateTime>
    </Contact>
  </content>
  <source>
    <id>http://api.constantcontact.com/ws/customers/anonymous/contacts</id>
    <title type="text">Contacts for Customer: anonymous</title>
    <link href="contacts"></link>
    <link href="contacts" rel="self"></link>
    <author>
      <name>anonymous</name>
    </author>
    <updated>2011-11-15T22:48:33.102Z</updated>
  </source>
</entry>


Please let me know if that worked for you.

Ryan Davis
Quality Engineer
Highlighted
Member

Re: Adding/removing contacts from lists

No that did not work. Contact is still on list 419 only. One thing I just thought to mention is that even though the initial contact creation was "ACTION_BY_CONTACT" I went in to our admin and moved it to 419 as I was unable to it through the API. I suspect that is why it changed to "ACTION_BY_CUSTOMER". Don't know if that creates a problem but if so I need a way of updating a contact's list if they choose to subscribe to different email lists using the API even if they were updated through admin.

Highlighted
Moderator

Re: Adding/removing contacts from lists

Is it possible for you to reproduce this in a REST Client (such as the one we reference here: http://community.constantcontact.com/t5/Documentation/How-To-Use-RESTClient/ba-p/24915) and save the reproduced case as an RCQ file.  If you can do this and send us the RCQ file, we can look at it internally and see what specifically is going on with this request.  The email address you can send this to is webservices@constantcontact.com.

Dave Berard
Senior Product Manager, 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