cancel
Showing results for 
Search instead for 
Did you mean: 
Constant Contact wants to help you succeed! We’re celebrating our professional service programs on the Constant Contact Community this month and you have a chance to try one of the services for free! Learn more.

400 from API with Ruby gem on contact creation

Highlighted
Occasional Contributor

400 from API with Ruby gem on contact creation

Hi all,

 

When I add a contact to my account (Wishery), using a POST request to https://api.constantcontact.com/ws/customers/wishery/contacts, it works. i get a 201 Created, I can see the contact, etc.

 

Strangely, when doing everything identically (same library, same function call) except using a different account (and different credentials), I'm getting a 400 Bad Request.

 

I'd appreciate resolution of this issue as I'm using the Ruby Constant Contact gem, and I'm not the only one having the problem. I'll submit a patch if we can get this worked out.

 

When creating a new contact, the gem emits the following XML:

 

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

       <title type=\"text\"> </title>

       <updated>2011-07-19T18:06:26Z</updated>

       <author></author>

       <id>data:,none</id>

       <summary type=\"text\">Contact</summary>

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

       <Contact xmlns=\"http://ws.constantcontact.com/ns/1.0/\"><EmailAddress>MCKPEAOX@wishery.com</EmailAddress><OptInSource>ACTION_BY_CUSTOMER</OptInSource><ContactLists><ContactList id=\"http://api.constantcontact.com/ws/customers/wishery/lists/1\"/></ContactLists></Contact>

       </content>

     </entry>

 

When using this on the account of user andsink, I get a 400 error.

 

Maybe the XML is missing some fields? It seems like it's working fine on account wishery, but not on andsink, and I'm not sure why. Maybe something about andsink's lists are configured in such a way that we can't use the same XML to add users to both of them?

 

Hmm...

 

DA

5 REPLIES 5
Occasional Contributor

Re: 400 from API with Ruby gem on contact creation

I should also state that I'm using OAuth. I think the OAuth is working fine though, because I'm getting a 400, and I think I'd get a 401 if there was an authorization problem. Is my understanding correct?

CTCT Employee

Re: 400 from API with Ruby gem on contact creation

Hello,

 

I took a look at your account and I do notice that you do not have a General Interest list.  I cannot access the account with the API, because it requires me to know your password.  However, the first thing I would check with the XML is that you still have a contact list ID 1.  Is it possible for you to do a GET on the lists uri, https://api.constantcontact.com/ws/customers/username/lists, and see if you have a valid list URI for the contact?

 

Also, you are correct, if you are getting a 400 error, more than likely you are authenticating correctly in OAuth.  Most of the time 400 errors are XML related.

 

I did test the XML on my end, and it does work as long as the contact list is correct.  If it is still not working for you after you verify that you are using a valid list ID, it may be beneficial to send me your entire code here.

 

Regards,

Benjamin Soder
NOC Analyst
Constant Contact
Occasional Contributor

Re: 400 from API with Ruby gem on contact creation

Thanks Benjamin, this is extremely helpful. I'm going to enumerate the lists in andsink now and get back to you in a few mins...

Occasional Contributor

Re: 400 from API with Ruby gem on contact creation

Hi again Benjamin,

 

When creating a new Contact record, the gem inserts the General Interest list into the generated XML. I have no idea why it does this, but it does -- this isn't something I requested or specified anywhere in code.

 

Is it customary or standard for all CTCT accounts to have a "General Interest" list? Put differently, is it the user's "fault" for deleting the list, or is the gem wrong to assume that this list will exist in every user's account, by default?

CTCT Employee

Re: 400 from API with Ruby gem on contact creation

Hi Cooper,

 

Spoiler

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

       <title type=\"text\"> </title>

       <updated>2011-07-19T18:06:26Z</updated>

       <author></author>

       <id>data:,none</id>

       <summary type=\"text\">Contact</summary>

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

       <Contact xmlns=\"http://ws.constantcontact.com/ns/1.0/\"><EmailAddress>MCKPEAOX@wishery.com</EmailAddress><OptInSource>ACTION_BY_CUSTOMER</OptInSource><ContactLists><ContactList id=\"http://api.constantcontact.com/ws/customers/wishery/lists/1\"/></ContactLists></Contact>

       </content>

     </entry>

You are specifying which list inside of the XML that you are posting.  Your ContactList id is your list number.  The default list or General Interest list is list 1, but you can change the XML accordingly. 

 

Regards,

Ryan Davis
Quality Engineer