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.

400 Bad Request creating a new campaign

SOLVED
Go to solution
user96514
Regular Participant

400 Bad Request creating a new campaign

Hi all

 

We are trying to create a campaign through your API. 

Sometimes it worked, but sometimes we received a 400 Bad Request, as in this case: 

method: POST url: https://api.cc.email/v3/emails payload: {'json': {'name': 'My new message-1571836258463', 'email_campaign_activities': [{'format_type': 1, 'from_email': 'cinzia.caleffi@beefree.io', 'from_name': 'cinzia.caleffi@beefree.io', 'reply_to_email': 'cinzia.caleffi@beefree.io', 'subject': '<%subject%>', 'html_content': '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional //EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">\n\n<head>\n\t<!--[if gte mso 9]><xml><o:OfficeDocumentSettings><o:AllowPNG/><o:PixelsPerInch>96</o:PixelsPerInch></o:OfficeDocumentSettings></xml><![endif]-->\n\t<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\n\t<meta name="viewport" content="width=device-width">\n\t<!--[if !mso]><!-->\n\t<meta http-equiv="X-UA-Compatible" content="IE=edge">\n\t<!--<![endif]-->\n\t<title></title>\n\t<!--[if !mso]><!-->\n\t<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet" type="text/css">\n\t<!--<![endif]-->\n\t<style type="text/css">\n\t\tbody {\n\t\t\tmargin: 0;\n\t\t\tpadding: 0;\n\t\t}\n\n\t\ttable,\n\t\ttd,\n\t\ttr {\n\t\t\tvertical-align: top;\n\t\t\tborder-collapse: collapse;\n\t\t}\n\n\t\t* {\n\t\t\tline-height: inherit;\n\t\t}\n\n\t\ta[x-apple-data-detectors=true] {\n\t\t\tcolor: inherit !important;\n\t\t\ttext-decoration: none !important;\n\t\t}\n\t</style>\n\t<style type="text/css" id="media-query">\n\t\t@media (max-width: 640px) {\n\n\t\t\t.block-grid,\n\t\t\t.col {\n\t\t\t\tmin-width: 320px !important;\n\t\t\t\tmax-width: 100% !important;\n\t\t\t\tdisplay: block !important;\n\t\t\t}\n\n\t\t\t.block-grid {\n\t\t\t\twidth: 100% !important;\n\t\t\t}\n\n\t\t\t.col {\n\t\t\t\twidth: 100% !important;\n\t\t\t}\n\n\t\t\t.col>div {\n\t\t\t\tmargin: 0 

*Code sample truncated*

 

Can someone understand what the problem is? 
Let me know if I can provide any additional information. 

Thanks!

1 ACCEPTED SOLUTION

add this to your header

 

"Content-Type: application/json; charset=utf-8";

 

it worked for us

View solution in original post

10 REPLIES 10
David_B.
Moderator

Hello,

 

I wasn't able to find anything inherently incorrect with the body of your email. Assuming that you have verified the email address being used as the from/reply, that should also be okay.

 

So taking a look at your sample, your payload is starting with an object called 'json', whereas the body should just contain the details. For example this:

{'json': {'name': 'My new message-1571836258463'....

 

should instead look like this:

{'name': 'My new message-1571836258463'....

with the closing bracket removed as well at the end.

 

Please give that a try and let me know if you're still having trouble.

 

Regards,

David B.
Tier II API Support Engineer

 

user96514
Regular Participant

Hi David

Thanks for your response.

 

Sorry for the midunderstangind on the payload, The "json" key is used by our log system, the actual payload sent to your API is already the value inside the "json" key, exactly as you suggest.

 

In fact, other request with same structure (but with a simpler html) works fine, but we don't understand what’s wrong in this payload content and why it returns a 400. 

I don't know if you can dig further but we are using this API Key: *****

Could you please look at your log and see what went wrong with this 400? 

I would appreciate it.
Cinzia

 

*edited to remove api key

user96514
Regular Participant

Please, can someone help me on this? 

 

Hi @user96514,

 

Sorry your message fell off. We'll take a look and get back to you.


Regards,
Jimmy D.
Tier II API Support Engineer
user96514
Regular Participant

Do you have any suggestions? 
We are keep getting this error.

add this to your header

 

"Content-Type: application/json; charset=utf-8";

 

it worked for us

View solution in original post

user96514
Regular Participant

Thanks, it works for us too  

Hi there,

We are facing the same issue, was your problem solved?

if yes can you please tell me the solution

user96514
Regular Participant

Sorry, but no, I didn't find any solution yet...

Developer Portal

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

Visit Page