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.

scheduling a campaign via API

SOLVED
Go to solution
Highlighted
Advisor

scheduling a campaign via API

Hello,

 

I am getting an error on the scheduling a campaign via API. Its a 400 bad request error. Do you want me to post the xml here or email to the App team? It has to do with my xml part..please advise.

 

thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Advisor

Re: scheduling a campaign via API

It works now.

 

Before I had 2011-4-11, when i changed that to 2011-04-11, then it worked without any problem. It was looking for a 2 digit number for months. Thanks for your help.

View solution in original post

12 REPLIES 12
Highlighted
Employee

Re: scheduling a campaign via API

If you are comfortable with posting it here you can certainly do that so that others might benefit from it as well. Otherwise, feel free to email it to our webservices support team and we'll be happy to take a look. Thanks!

David J

Highlighted
Advisor

Re: scheduling a campaign via API

Sure I can post it here. 

 

 

This is my XML.

string createCampaign = @"<?xml version=""1.0"" encoding=""UTF-8"" ?> 
            <entry xmlns=""http://www.w3.org/2005/Atom"">
            <link href=""/ws/customers/abc/campaigns/" + campaignId + @"/schedules/1"" rel=""edit"" /> 
            <id>http://api.constantcontact.com/ws/customers/abc/campaigns/" + campaignId + "/schedules/1" + @"</id> 
            <title type=""text"">2010-11-13T15:03:35Z</title> 
            <updated>2010-11-13T20:03:35.000Z</updated> 
            <author> <name>Constant Contact</name> </author> 
            <content type=""application/vnd.ctct+xml""> 
            <Schedule xmlns=""http://ws.constantcontact.com/ns/1.0/"" id=""http://api.constantcontact. com/ws/customers/abc/campaigns/" + campaignId + @"/schedules/1""> 
            <ScheduledTime>" + DateTime.Now.AddDays(3) + @"T20:03:35.000Z</ScheduledTime> </Schedule> 
            </content> 
            </entry>";

 

I am getting a 400 Bad Error request.

 

Highlighted
Employee

Re: scheduling a campaign via API

Your XML looks correct to me, and did schedule a campaign in my own account. Do you know if the campaign you are trying to schedule has any contact lists associated with it. If there are no contact lists that the campaign is able to send to, it will return the following error:

 

Error 400: No contacts to send.

David J

Highlighted
Advisor

Re: scheduling a campaign via API

I forgot to give you the full error. The error says "Schedule cannot be in the past".

 

I changed the scheduledTime to be 3 days from today. Is that not set correct?

 

Also, this campaign has a list attached to it. Also, its in Draft status. 

Highlighted
Employee

Re: scheduling a campaign via API

The following scheduled time works correctly for me, which is November of this year:

 

<ScheduledTime>2011-11-13T20:03:35.000Z</ScheduledTime>

 

Does that node work for you? If so then we know it's something with the way your date/time is being constructed.

David J

Highlighted
Advisor

Re: scheduling a campaign via API

When i hardcoded the date to November, then it worked. 

 

I changed the scheduled date to 2011-4-11, but it still says Schedule cannot be in the past. It works for November but not for 3 days from today.  I can try some other dates too..

Highlighted
Advisor

Re: scheduling a campaign via API

It works now.

 

Before I had 2011-4-11, when i changed that to 2011-04-11, then it worked without any problem. It was looking for a 2 digit number for months. Thanks for your help.

View solution in original post

Highlighted
Moderator

Re: scheduling a campaign via API

An easier way to convert the DateTIme for the XML is usually to do something like this to convert it for you:

 

DateTime.Now.AddDays(3).ToUniversalTime().ToString("o");

 

This will automatically put it into the correct time zone and format for the XML.  This can be used for any DateTime object you create and you'll not have to worry about formatting or converting it in any way. 

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Occasional Participant

Re: scheduling a campaign via API

This is me campaign object that I am sending for scheduling via PHP wrapper

Campaign Object ( [name] => testing going on - 2014-08-08T12:55:57.000Z [id] => http://api.constantcontact.com/ws/customers/{id}/campaigns/{campaign id} [link] => /ws/customers/{id}/campaigns/{campaign id} [status] => Draft [campaignDate] => 2014-08-08T07:26:19.717Z [lastEditDate] => 2014-08-08T07:26:19.717Z [lastRunDate] => [campaignSent] => 0 [campaignOpens] => 0 [campaignClicks] => 0 [campaignBounces] => 0 [campaignForwards] => 0 [campaignOptOuts] => 0 [campaignSpamReports] => 0 [subject] => testing going on [fromName] => vandana [campaignType] => CUSTOM [vawp] => NO [vawpLinkText] => [vawpText] => [permissionReminder] => NO [permissionReminderText] => [greetingSalutation] => Dear [greetingName] => FirstName [greetingString] => [orgName] => test [orgAddr1] => org [orgAddr2] => test [orgAddr3] => tes [orgCity] => test [orgState] => WB [orgInternationalState] => [orgCountry] => IND [orgPostalCode] => 123445 [incForwardEmail] => NO [forwardEmailLinkText] => [incSubscribeLink] => NO [subscribeLinkText] => [emailContentFormat] => HTML [emailContent] => testing [textVersionContent] => Mail [styleSheet] => [lists] => Array ( [0] => /ws/customers/{id}/lists/{list id} ) [fromAddress] => VerifiedAddress Object ( [email] => {mail} [status] => [verifiedTime] => [id] => [link] => /ws/customers/{id}/settings/emailaddresses/23 [updated] => ) [replyAddress] => VerifiedAddress Object ( [email] => {mail} [status] => [verifiedTime] => [id] => [link] => /ws/customers/{id}/settings/emailaddresses/29 [updated] => ) [archiveStatus] => [archiveUrl] => [urls] => Array ( ) )

calling the scheduling API -

$CampaignResultCurrent = $ConstantContact->getCampaignByID($CampaignId);
$schedule = $ConstantContact->scheduleCampaign($CampaignResultCurrent,$scheduletime);

I am getting error 400 - No contacts to send.
When I check the account - list is added and contacts are also getting added but in draft mode.
Not sure, what is happening.
Please reply.
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