I'm trying to schedule a campaign that is in DRAFT mode and has a list with 2 recipients, but I keep recieving "The requested URL returned error: 400" on the POST. The XML I'm sending is below and I've changed the User Name. Is there something missing or wrong with the request.
Also, I'm sending it to:
https://api.constantcontact.com/ws/customers/UserName/campaigns/1106656877078/schedules
<?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom"> <link href="/ws/customers/UserName/campaigns/1106656877078/schedules/1" rel="edit"/> <id>http://api.constantcontact.com/ws/customers/UserName/campaigns/1106656877078/schedules/1</id> <title type="text">2011-07-19T14:33:05.000Z</title> <updated>2011-07-19T14:33:05.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/UserName/campaigns/1106656877078/schedules/1"> <ScheduledTime>2011-07-19T14:33:05.000Z</ScheduledTime> </Schedule> </content> </entry>
Solved! Go to Solution.
Hello,
I tried your XML and it did fail on my end due to it being in the past. When I changed the date it did succeed. Are you scheduling the email to go out after the time that it is? Please keep in mind that the time must be in UTC, not your current time zone.
Regards,
Hello,
I tried your XML and it did fail on my end due to it being in the past. When I changed the date it did succeed. Are you scheduling the email to go out after the time that it is? Please keep in mind that the time must be in UTC, not your current time zone.
Regards,
Thanks Ben! That was it, I was scheduling it to be sent +1 hour from my time zone instead of the UTC time.
No problem! If you run into any other issues let me know!
Regards,
Hi All,
will you please look at my code for "Scheduling Campaign", i have a camapign in DRAFT and "Scheduling" is active by the team but when i am trying to POST this code am getting nothing
POST url :https://api.constantcontact.com/ws/customers/username/campaigns/1106995949451/schedules
so please help me and let me know where i am doing wrong, here is my XML
<?xml version="1.0" encoding="UTF-8"?> <entry xmlns="http://www.w3.org/2005/Atom">
<link href="/ws/customers/username/campaigns/1106995949451/schedules/1" rel="edit" />
<id>http://api.constantcontact.com/ws/customers/username/campaigns/1106995949451/schedules/1</id>
<title type="text">title</title>
<updated>2011-08-08T08:51:57.000Z</updated>
<author> <name>kilgorenewsherald</name> </author>
<content type="application/vnd.ctct+xml">
<Schedule xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/username/campaigns/1106995949451/schedules/1"> <ScheduledTime>2011-07-09T20:03:35.000Z</ScheduledTime>
</Schedule>
</content>
</entry>
I reviewed your XML and did not find any errors. Can you elaborate on the error you are receiving when doing the POST?
Please keep in mind that the time must be in UTC when scheduling, not your current time zone.
Hi Matt_D,
Actually i am not getting any error message too while trying to POST my XML, will you please take a look to my complete code for posting XML to server and let me know where i am doing wrong
XML code:
$updatetime = gmdate("Y-m-d\TH:i:s").".000Z";
$entry = '';
$entry .= '<?xml version="1.0" encoding="UTF-8"?>';
$entry .= '<entry xmlns="http://www.w3.org/2005/Atom">';
$entry .= '<link href="/ws/customers/username/campaigns/1106995949451/schedules/1" rel="edit" />';
$entry .= '<id>http://api.constantcontact.com/ws/customers/username/campaigns/1106995949451/schedules/1</id>';
$entry .= '<title type="text">Title</title>';
$entry .= '<updated>'.$updatetime.'</updated>';$entry .= '<author>';
$entry .= '<name>kilgorenewsherald</name>';
$entry .= '</author>';
$entry .= '<content type="application/vnd.ctct+xml">';
$entry .= '<Schedule xmlns="http://ws.constantcontact.com/ns/1.0/" id="http://api.constantcontact.com/ws/customers/username/campaigns/1106995949451/schedules/1">';
$entry .= '<ScheduledTime>2011-08-10T07:00:00.000Z</ScheduledTime>';
$entry .= '</Schedule>';
$entry .= '</content>';
$entry .= '</entry>';
//calling function here
$return_value = $ccCampaignOBJ->scheduleCampaign($entry);
public function scheduleCampaign($campaignXML) {
$call = 'https://api.constantcontact.com/ws/customers/username/campaigns/1106995949451/schedules';
$return = $this->doServerCall_test($call, $campaignXML, 'POST');
$parsedReturn = simplexml_load_string($return);
if ($return) {
return true;
} else {
$xml = simplexml_load_string($campaignXML);
$cmp_id = $xml->content->Schedule->Attributes();
$cmp_id = $cmp_id['id'];
$cmp_name = $xml->content->Campaign->Name;
if(!empty($cmp_id)) {
$search_status = $this->campaignExists($cmp_id, $cmp_name);
switch($search_status){
case 0:
$error = 'An Error Occurred. The campaign could not be added.';
break;
case 1:
$error = 'The name of the campaign already exist. Each campaign must have a distinct name.';
break;
case 2:
$error = 'This campaign already exists.';
break;
default:
$error = 'An Error Occurred. The campaign could not be added.';
}
$this->lastError = $error;
} else {
$this->lastError = 'An Error Occurred. The campaign could not be added.';
}
return false;
}
}
//calling CURL here
protected function doServerCall_test($request, $parameter = '', $type = "GET") {
$ch = curl_init();
$request = str_replace('http://', 'https://', $request);
// Convert id URI to BASIC compliant curl_setopt($ch, CURLOPT_URL, $request);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $this->requestLogin);
# curl_setopt ($ch, CURLOPT_FOLLOWLOCATION ,1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type:application/atom+xml", 'Content-Length: ' . strlen($parameter)));
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
switch ($type) {
case 'POST':
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameter);
break;
case 'PUT':
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameter);
break;
case 'DELETE':
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
break;
default:
curl_setopt($ch, CURLOPT_HTTPGET, 1);
break;
}
$emessage = curl_exec($ch);
if ($this->curl_debug) {
echo $error = curl_error($ch);
}
curl_close($ch);
return $emessage;
}
Any luck looking at this, Matt or Ryan?
just out of curiousity, you are using the real username, and not "username" in the urls, correct?
Hi,
yes i am using the real username in my code
Hi Derek,
Can you verify if you have curl_debug set to true or false in your code?
Also please email me your username to webservices@constantcontact.com so I can look into any account issues.
OK, I just e-mailed it to you.
And curl debug is set to false.
Thanks for forwarding us your username. I reviewed your account and found the approval process for the Scheduling API was completed but not fully propagated yet until this morning. You should be all set now to use the Schedule API.
Also, having debug set to false is why you were not receiving an error message. Setting this to true will help when troubleshooting issues.
The holidays have come and gone. For many seasonal businesses, this means the rush of shoppers has decreased as well. Instead of turning off the lights and waiting for spring, make your email marketi...
See Article