Got a 'How do I' question? Join 'Ask a Trainer' Monday to Friday, 11am to 4pm ET for instant help and pro tips!

400 Bad Request creating a new campaign

SOLVED
Go to solution
user96514
Campaign Collaborator
0 Votes

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
edivodev
Campaign Expert

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.
Employee
0 Votes

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
Campaign Collaborator
0 Votes

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
Campaign Collaborator
0 Votes

Please, can someone help me on this? 

 

Jimmy_D
Employee
0 Votes

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
Campaign Collaborator
0 Votes

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

edivodev
Campaign Expert

add this to your header

 

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

 

it worked for us

user96514
Campaign Collaborator

Thanks, it works for us too :smileyface: 

edivodev
Campaign Expert
0 Votes

Hi there,

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

if yes can you please tell me the solution

user96514
Campaign Collaborator
0 Votes

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

Resources
Developer Portal

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

Visit Page

Announcements

API Updates

Join our list to be notified of new features and updates to our V3 API.

Sign Up