This is not a typical post, but I just had to share as it took me a good afternoon of trial error to figure out how to add a new contact to a Constant Contact account using their REST API. Their documentation has many holes, but fortunately the API works well.

After you've authenticated, here's the XML required to add a new subscriber:

<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <link href="/ws/customers/username/contacts" rel="edit"></link>
  <id>http://api.constantcontact.com:443/ws/customers/username/contacts</id>
  <title type="text">Contact: [email protected]</title>
  <updated>2011-02-27T18:48:00.760Z</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:443/ws/customers/username/contacts">
      <Status>Active</Status>
      <EmailAddress>[email protected]</EmailAddress>
      <OptInSource>ACTION_BY_CUSTOMER</OptInSource>
      <EmailType>HTML</EmailType>
      <Name>this doesn't seem to work - use firstname & lastname instead</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:443/ws/customers/username/lists/2">
          <link xmlns="http://www.w3.org/2005/Atom" href="/ws/customers/username/lists/2" rel="self"></link>
          <OptInSource>ACTION_BY_CONTACT</OptInSource>
          <OptInTime>2011-02-27T18:48:00.810Z</OptInTime>
        </ContactList>
      </ContactLists>
      <Confirmed>true</Confirmed>
      <InsertTime>2011-02-27T18:48:00.760Z</InsertTime>
      <LastUpdateTime>2011-02-27T18:48:00.760Z</LastUpdateTime>
    </Contact>
  </content>
  <source>
    <id>http://api.constantcontact.com:443/ws/customers/username/contacts</id>
    <title type="text">Contacts for Customer: username</title>
    <link href="contacts"></link>
    <link href="contacts" rel="self"></link>
    <author>
      <name>username</name>
    </author>
    <updated>2011-06-03T17:14:10.175Z</updated>
  </source>
</entry>

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *