List Creation

jcresswell
Participant

List Creation

I'm currently trying to implement a library to use the REST APIs for a client site. I'm trying to get the Create New List. From the documentation it says:




"A new Contact list is created by making an HTTP POST to the collection URI. The POST body must contain an Atom entry element that includes the content for the new list."


Looking at this, I cannot see what the variable name should be that I am posting back, or if I am missing a bigger picture item, does anyone have a PHP example of doing this using CURL?

5 REPLIES 5
kmandeville
Occasional Participant

We have a PHP Sample Application that is available for download on this page http://developer.constantcontact.com/doc/samples. This sample application does not include List Creation functionality, but you can look at fileUpload.php for an example of using CURL to perform a POST. This PHP page creates a new Activity resource, so the data being posted is a bit different. It's not posting an Atom entry, but it's posting name/value pairs. The only differences will be in the CURLOPT_POSTFIELDS value and the Content-type. You will have to create a string variable with the XML for the Atom entry, and set that to the CURLOPT_POSTFIELDS variable (see the code for reference). You will also have to set the Content-type to be "application/atom+xml". You can do this by setting the CURLOPT_HTTPHEADER value using the curl_setopt function. This value must be set to an array, so you can set it like this:

curl_setopt($session, CURLOPT_HTTPHEADER, array('Content-Type: application/atom+xml');

If you have any other questions, please let us know.

Kevin Mandeville
Senior Engineer
Constant Contact.

It is not clear what the ID tag should contain. Please give a look on the following XML. For more informaion, please refer: http://community.constantcontact.com/t5/Documentation/Creating-a-New-List/ba-p/25069

 

<entry xmlns="http://www.w3.org/2005/Atom">
  <id>data&colon;;,</id>
  <title />
  <author />
    <updated>2008-04-16</updated>
    <content type="application/vnd.ctct+xml">
    <ContactList xmlns="http://ws.constantcontact.com/ns/1.0/">
      <OptInDefault>false</OptInDefault>
            <Name>A New List</Name>
            <SortOrder>99</SortOrder>
        </ContactList>
    </content>
</entry>

Hi,

 

Sorry, our online text editor insists on encoding colons in certain cases, which is what happened with the example you saw.  I've put up sample new list XML here in Github.  You want to replace "&colon;" with ":".

 

Best Regards,

Shannon W.

API Support Specialist

Thank you for you reply. Could you tell me what the data means here in tag "<id>data&colon;;,</id>"?

Hi Uday,

 

The contents of the id node allow our internal services to handle the XML payload properly.  Quite honestly, I'm not sure why the id node was exposed through the API.  Its value must always stay the same; the data, colon, semi-colon, and comma inside the id node should remain as I posted it on Github.  Otherwise, a 400 or other error may occur.

 

Best Regards,

Shannon W.

API Support Specialist

Developer Portal

View API documentation, code samples, get your API key.

Visit Page