400 error message

Regular Participant

400 error message

I am trying to use this example.  I am getting a 400 error and can't figure it out.  Here is my XML portion:

 

' Adding a contact

 

strPostData = "<entry xmlns=""http://www.w3.org/2005/Atom"">" &vbCrLF
strPostData = strPostData & "<title type=""text""> </title>" &vbCrLF
strPostData = strPostData & "<updated>2008-07-23T14:21:06.407Z</updated>" &vbCrLF
strPostData = strPostData & "<author></author>" &vbCrLF
strPostData = strPostData & "<id>data:,none</id>" &vbCrLF
strPostData = strPostData & "<summary type=""text"">Contact</summary>" &vbCrLF
strPostData = strPostData & "<content type=""application/vnd.ctct+xml"">" &vbCrLF
strPostData = strPostData & "<Contact xmlns=""http://ws.constantcontact.com/ns/1.0/""" &vbCrLF
strPostData = strPostData & "<EmailAddress>"&EmailAddress&"</EmailAddress>" &vbCrLF
strPostData = strPostData & "<OptInSource>ACTION_BY_CONTACT</OptInSource>" &vbCrLF
strPostData = strPostData & "<ContactLists>" &vbCrLF
strPostData = strPostData & "<ContactList id=""http://api.constantcontact.com/ws/customers/"&UN&"/lists/"&List_ID&""" />" &vbCrLF
strPostData = strPostData & "</ContactLists>" &vbCrLF
strPostData = strPostData & "</Contact>" &vbCrLF
strPostData = strPostData & "</content>" &vbCrLF
strPostData = strPostData & "</entry>" &vbCrLF

 

11 REPLIES 11
Employee

Hey Matt,

 

I moved your post as the 400 error does not relate to the 401 error that was happening in that previous post.  The 400 error is a "Bad Request" error.  This is happening based on the XML.  Can you get the data that is being passed in to our API so that I can see the end result of the XML itself.

Ryan Davis
Quality Engineer
Regular Participant

the variables I am passing are:

 

EmailAddress: mattCCtest@xxxxx.com

List_ID: test   (I created a list called test)

Method: POST

UN:  mdzXXXXX  (user name)

Pass: zanXXXXXXX  (pasword)

API_Key: 15c736ef-xxxx-xxxx-xxxx-xxxxxxx

 

 

 

Hey Matt,

 

The variable of your list id needs to be a numerical list ID.  If you do a get to your list collection you will be able to see all of your lists and their corresponding ID's.  Also the ID can be found in the User Interface by hovering over the link name.  You can see a picture of this here.  Where listID=11 in my example yours can be any number. 

 

Let me know if this works.

Ryan Davis
Quality Engineer
Regular Participant

that's it!  I also found a missing ">" in my xml code. 

 

Thanks for the quick replies.

No problem Matt, let me know if you need anymore help.

Ryan Davis
Quality Engineer
Regular Participant

I am having trouble finding examples on GET TING the contacts's id. 

Hey Matt,

 

If you were getting the contacts id you would use the searchbyemailaddress URI and it would return the contacts information or that the contact email address didn't exist.  From there you would just parse the data accordingly.

Ryan Davis
Quality Engineer
Regular Participant

looking at what was returned, it doesn't look like it includes what lists the contact is subscribed to.  Did I miss something?

 

<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>http://api.constantcontact.com/ws/customers/mdXXXX/contacts</id>
  <title type="text">Contacts for Customer: mdXXXX</title>
  <link href="contacts"></link>
  <link href="contacts" rel="self"></link>
  <author>
    <name>mdXXXX</name>
  </author>
  <updated>2011-10-06T21:50:36.227Z</updated>
  <link href="/ws/customers/XXXX/contacts" rel="first"></link>
  <link href="/ws/customers/XXXX/contacts?email=mattCCtest%40XXXX.com" rel="current"></link>
  <entry>
    <link href="/ws/customers/XXXXX/contacts/88887" rel="edit"></link>
    <id>http://api.constantcontact.com/ws/customers/mdXXXX/contacts/88887</id>
    <title type="text">Contact: mattcctest@XXXXcom</title>
    <updated>2011-10-06T21:50:36.336Z</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/mdXXXX/contacts/88887">
        <Status>Active</Status>
        <EmailAddress>mattcctest@XXXX.com</EmailAddress>
        <EmailType>HTML</EmailType>
        <Name></Name>
        <OptInTime>2011-10-06T21:00:40.267Z</OptInTime>
        <OptInSource>ACTION_BY_CONTACT</OptInSource>
        <Confirmed>true</Confirmed>
        <InsertTime>2011-10-06T21:00:40.267Z</InsertTime>
      </Contact>
    </content>
  </entry>
</feed>

Do a GET to

 

<link href="/ws/customers/XXXXX/contacts/88887" rel="edit"></link>

 so contacts/88887 which will give you this particular contact.

Ryan Davis
Quality Engineer
Regular Participant

so it wold be a two step process if I only have the email address?  First get returns the ID, then a get with the id returns the lists?

Hey Matt,

 

Yes that is how it works.  It follows the same steps as our user interface.

Ryan Davis
Quality Engineer
Developer Portal

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

Visit Page