The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Schedule Email Campaign

Highlighted
Occasional Contributor

Schedule Email Campaign

I need a serious help.
Need help on scheduling campaign using asp.net. 
I have already configured my constant contact account to use api and I was success on using other api such as:

1. Retrieve Contact

2. AddContact

3. Read/Write ContactList

..

I was trying to schedule campaign and to do that I used HttpClient. I know have correct json data to post it. But when I make api call it always return Error:400, BadRequest.
My asp.net code looks like as below:

 

String jsonData = "{\"scheduled_date\":" + "\"2017-12-09T12:34:59Z\"}";
string requestPath = "emailmarketing/campaigns/"+id+"/schedules" + api;
string jsonContact = jsonData;
StringContent content = new StringContent(jsonContact, UnicodeEncoding.UTF8, "application/json");
content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

HttpClient client = new HttpClient();
client.BaseAddress = new Uri(baseAddress); //baseAddress = https://api.constantcontact.com/v2/
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken);
var response = client.PostAsync(requestPath, content).Result;

 

I am not sure whats going wrong in the code it always sends Error:400. Is there any other alternative to achieve it.

 

Thanks in advance.

2 REPLIES 2
Highlighted
Moderator

Re: Schedule Email Campaign

Hello,

 

There are a few different things that can cause a 400 error. What is the error response message that is being returned with the error code 400? For example, "Property was found but is not permitted at this location" or "Unable to parse JSON payload"

 

These will be key to determining why your call is being rejected.

 

Regards,
David B.
Tier II API Support Engineer

Highlighted
Occasional Contributor

Re: Schedule Email Campaign

Thanks for the response. I was able to fix the error. 

Developer Portal

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

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured