scheduling a campaign via API

SOLVED
Go to solution
StrategicA1
Member

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

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
David_J
Employee

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

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.

 

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

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. 

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

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..

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

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
AnirbanM
Regular Participant

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.

Hello,

 

I have reviewed the data you provided, and it is correct along with the PHP wrapper code. After looking a bit deeper in the Constant Contact account that you have been testing with, it appears that you are deleting the lists associated with these campaigns before you have time to schedule and send them. It is definitely possible to create a list with a specialized subset of your contacts, send a campaign to them, and then delete that list. If you do want to use a process like this, it is important to make sure that the list is not deleted before the campaign is done sending.

 

I would suggest double-checking your code to make sure that your lists are not being deleted before you attempt to schedule the campaign. If the list is deleted, then there will be no contacts to send the campaign to even though it has a list ID assigned.

 

Best Regards,

Elijah G.
API Support Engineer
AnirbanM
Regular Participant

Hi Elijah,

 

Thanks for your reply. 

I am not deleting any list via code. For each campaign I am adding one list and them schedule it. Lots of junk test list got created during development so I deleted them manually.

 

I just want to know, is there any limitation on the number of times a same contact can be added to the list(newly created), if the contact exists in other lists?

 

The nature of this error 400 is random, sometimes everything works well and sometimes it throws this error - Error 400: No contacts to send

I noticed that maximum time the error get poppep-up when I sent out same set of email IDs to the list and try to schedule it, during scheduling only the warning comes, rest everything works fine. But I am not sure what is the exact reason.

 

I am doing following things:

1) creating an array of contacts to addition to list

2) Add a new list to constant contact account

3) Using bulkAddContacts - add the contacts to list

4) Add the Campaign

5) If campaign is added successfully then schedule it - (here, Error 400: No contacts to send comes into picture)

 

If you want I can mail you the codes( my email is [REDACTED])

 

Thanks & Regards,

Vandana

Hi Vandana,

 

There is not a limit on how many times a contact can be added to a newly created list if they are already a member of a different list. The only potential limitation that you may experience here is that each Constant Contact account is limited to having 1,000 lists at any time.

 

Based on your steps, I think it would be worthwhile to review some specific campaigns that have failed to send and see if we can find any information on what is happening. It may also be helpful to have an excerpt of the code that create and sends campaigns as well.

 

The easiest way to review this information is for you to reach out to us by email at webservices@constantcontact.com.

 

Best Regards,

Elijah G.
API Support Engineer
Developer Portal

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

Visit Page