cancel
Showing results for 
Search instead for 
Did you mean: 

Error 400 received when making post method call

Occasional Contributor

Error 400 received when making post method call

Few mins back I was trying to make api post method request thru MVC5 Application

URL: https://api.constantcontact.com/v2/emailmarketing/campaigns/1129304050440/schedules?api_key=8d6pv***...

My request body was like such below:

"{\"scheduled_date\" : \"2017-12-01T17:50:31Z\"}"

 

and I received an error like below:

 

{StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
X-Mashery-Responder: prod-j-worker-us-east-1e-130.mashery.com
Connection: keep-alive
Date: Fri, 01 Dec 2017 17:48:18 GMT
Server: Apache
Content-Length: 115
Content-Type: application/json; charset=UTF-8
}}

 

I could not understand what mistake did I made, would any one suggest me whats going wrong there

 

2 REPLIES 2
Moderator

Re: Error 400 received when making post method call

Hello,

Thank you for reaching out to Constant Contact API Support.

I see you are escaping the "s in your request data and also putting the whole thing in quotes. Are you setting this as a JSON string, and is it including your escape slashes and/or the quotes around the {}s? The contents of your data when received by Constant Contact's API should look like:

 

{"scheduled_date" : "2017-12-01T17:50:31Z"}

 

Regards,
David B.
Tier II API Support Engineer

Occasional Contributor

Re: Error 400 received when making post method call

I am setting this as json string. Even though still sending me same error.

I would like you to share my code which make a api call to schedule email.
My code looks like below:

 

DateTime dt = System.DateTime.Now.AddMinutes(10);
string dateISO = dt.ToString("yyyy-MM-ddTHH:mm:ssZ");

Models.schedule_campaign schedule = new Models.schedule_campaign();
schedule.scheduled_date = dateISO;
string requestPath = "emailmarketing/campaigns/"+id+"/schedules" + api;
string jsonContact = Newtonsoft.Json.JsonConvert.SerializeObject(schedule);
var content = new StringContent(jsonContact);
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
HttpResponseMessage response = HttpClient.PostAsync(requestPath, content).Result;

 

Where schedule is my model and is defined as:

public class schedule_campaign
{
public string scheduled_date { get; set; }
}