We all started somewhere! Share your experience on the Get Advice: Let's Get Started Sweepstakes thread and be entered to win a $100 credit on your Constant Contact account.

Another 400 error when creating a campaign.

MarkC148
Regular Participant

Another 400 error when creating a campaign.

Hi,

  I am trying to create  new campaigns when saving a node in Drupal. I believe I have the proper XML but I keep getting a 400 error. Can you take a look at the text here: https://gist.github.com/anonymous/784d778772a4244ea65e and let me know what I can do to make this a successful response.

 

Mark

13 REPLIES 13
Shannon_W
Employee

Hi Mark,

 

After changing account-specific details, I got a 201 Created response with your XML.  That means the discrepancy must be with the verified email address, list ID (18), or username.  The most likely issue is that the email address you referenced in the replyto and fromemail nodes is not the 13th verified email address in the account.  

 

Here you can see how to obtain a list of verified email addresses in your account and their corresponding ID's.

 

Best Regards,

Shannon W.

API Support Specialist

Shannon,

  Thanks for the quick reply. I verified all of the things you have pointed out. I was able to get the verified emails as suggested, so the API key and username is correct, and the resulting search did show that the reply email and id are correct. Also I verifed that the list id is correct, and even tried different lists to no avail. 

 

  The program I have building this was working previously. I remember when we started this, we had to do something to allow this user (afpcmail) to generate campaigns through the API. Can we verify that this is still valid?

Hi,

 

That is strange.  What is the text response from our server accompanying the 400 response code?  Often those can be helpful in determining the issue.

 

Best Regards,

Shannon W.

API SUpport Specialist

MarkC148
Regular Participant

The response body is FALSE, and the error code is 400. No other text was returned. Here's the curl_getinfo() of the request:

 

http_response_info (Array, 21 elements)

Hi,

 

I can see that we're providing you a 62 character failure response along with the 400 error in our response to your calls to our server, but sadly I can't see what it is.

 

Could you use a restclient to send the XML payload to us, and look at the response it generates?  I'm partial to browser plugin restclients, but any restclient should show you the full response back.

 

Best Regards,

Shannon W.

API Support Specialist

MarkC148
Regular Participant

Shannon,

  Is there some time we can get together on GoToMeeting or some other live chat? I am having a wierd issue with the RESTClient now and really need someone to hold my hand apparently. Please let me know.

 

mark

Hi Mark,

 

We can try to accommodate you but aren't able to guarantee phone calls.  Email webservices@constantcontact.com with a few dates and times that would work for you, and we will try to make it work.

 

Just a few basics, this is the information you should need in restclients:

 

URL (complete it): 

 

https://api.constantcontact.com/ws/customers/af...

 

 

Headers:  You'll need to choose between basic and OAuth2, which requires an access token.  If you don't have an access token, you should base64 encode this string, with your own credentials filled in: apiKey%username:password

 

Authorization: Basic your_base64_encoded_string
content-type: application/atom+xml

 

 If you already have an access token, you can use:

 

Authorization: Bearer access_token_value
content-type: application/atom+xml

 

 

Body:

Your XML

 

Best Regards,

Shannon W.

API Support Specialist

MarkC148
Regular Participant

Shannon,

  No need to set up a call as that was the perfect amount of hand holding (I forgot to prepend the API Key when logging into the RESTClient)

 

  So now I am seeing the full response and getting an Error400: Invalid or Missing <EmailContent>. However when I validate my XML, passes validation. Here's the gist of it

 

https://gist.github.com/anonymous/0e9abb203d77b4b7007d

 

As you can see, the EmailContent node is present. 

  

 

mark

Hi Mark,

 

I just had time to change the username, verified email address, and from/reply-to email address id in your sample XML to make it match my account settings, and I still got a 201 Created (success) message back.  That's of course perplexing that it didn't work for you.

 

What happens when you change your email content node to the following?

 

<EmailContent>&lt;html&gt;&lt;body&gt;Hello!&lt;/body&gt;&lt;/html&gt;</EmailContent>

 

 

Best Regards,

Shannon W.

API Support Specialist

MarkC148
Regular Participant

When I change to just a hello page, it works for me. 

It sounds like the issue is that your server is cutting off the request because of the length of the email content node, so we're not getting the full request. 

MarkC148
Regular Participant

Yes I can send a plain email. I definitely think it's the character encoding that is killing me. Is it possible to create a campaign with a UTF-16 encoding?

Hello Mark,

 

Unfortunately the API and our emails are handled using UTF-8 for content encoding. Because of this, even if your data was sent using UTF-16, it is very likely that it would not be interpreted correctly if it was accepted at all.

 

After spending some time investigating the cause, there were several accented characters and some other unencoded characters that were being submitted and were not accepted by Constant Contact. To correct this, I used the PHP htmlentities function with the following flags to re-encode the contents:

htmlentities($content, ENT_COMPAT | ENT_HTML401 | ENT_SUBSTITUTE)

 

After doing this, the code was accepted by the API and submitted properly. You can view an updated XML request with this information here:

https://gist.github.com/anonymous/fa5a6670f115c5fbc88f

 

Sincerely,

Elijah G.

Tier 2 Support

Elijah G.
API Support Engineer
Developer Portal

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

Visit Page