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.

Error 400 when adding a new campaign

Highlighted
Occasional Contributor

Error 400 when adding a new campaign

Hello

 

I'm trying to create an email campaign using the php ctctWrapper library and I keep getting the 400 error. This is my code:

 

$params['id'] = '5436534';
$params['link'] = '6436436';
$params['campaign_name'] = 'Test email';
$params['status'] = 'Draft';
$params['campaign_date'] = date('Y-m-d');
$params['subject'] = 'Test subject';
$params['from_name'] = 'Test name';
$params['campaign_type'] = '';
$params['view_as_web_page'] = 'NO';
$params['vawp_link_text'] = '';
$params['vawp_text'] = '';
$params['permission_reminder'] = 'NO';
$params['permission_reminder_txt'] = '';
$params['greeting_salutation'] = 'Dear';
$params['greeting_name'] = 'FirstName';
$params['greeting_string'] = 'Greetings';
$params['org_name'] = 'Organization name';
$params['org_address_1'] = 'address...';
$params['org_city'] = 'City';
$params['org_country'] = 'Country';
$params['include_forward_email'] = 'NO';
$params['forward_email_link_text'] = '';
$params['include_subscribe_link'] = 'NO';
$params['subscribe_link_text'] = '';
$params['email_content_format'] = 'HTML';
$params['email_content'] = 'Some test content';


$Campaign = new Campaign($params);
$Campaigns = new CampaignsCollection();
$result = $Campaigns->createCampaign($Campaign);
print_r($result);

 

And this is the xml the createCampaignXml method returns:

SimpleXMLElement Object
(
    [link] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [href] => /ws/customers/name/campaigns
                    [rel] => edit
                )
        )
    [id] => http://api.constantcontact.com/ws/customers/name/campaigns
    [title] => Test email
    [updated] => 2011-10-14T17:28:31+01:00
    [author] => SimpleXMLElement Object
        (
            [name] => Constant Contact
        )
    [content] => SimpleXMLElement Object
        (
            [@attributes] => Array
                (
                    [type] => application/vnd.ctct+xml
                )
            [Campaign] => SimpleXMLElement Object
                (
                    [@attributes] => Array
                        (
                            [xmlns] => http://ws.constantcontact.com/ns/1.0/
                            [id] => http://api.constantcontact.com/ws/customers/name/campaigns/1100546096289
                        )
                    [Name] => Test email
                    [Status] => draft
                    [Date] => 2011-10-14T17:28:31+01:00
                    [Subject] => Test subject
                    [FromName] => Test name
                    [ViewAsWebpage] => NO
                    [ViewAsWebpageLinkText] => SimpleXMLElement Object
                        (
                        )
                    [ViewAsWebpageText] => SimpleXMLElement Object
                        (
                        )
                    [PermissionReminder] => NO
                    [PermissionReminderText] => SimpleXMLElement Object
                        (
                        )
                    [GreetingSalutation] => Dear
                    [GreetingName] => FirstName
                    [GreetingString] => Greetings
                    [OrganizationName] => Organization name
                    [OrganizationAddress1] => adress...
                    [OrganizationAddress2] => SimpleXMLElement Object
                        (
                        )
                    [OrganizationAddress3] => SimpleXMLElement Object
                        (
                        )
                    [OrganizationCity] => City
                    [OrganizationState] => SimpleXMLElement Object
                        (
                        )
                    [OrganizationInternationalState] => SimpleXMLElement Object
                        (
                        )
                    [OrganizationCountry] => Country
                    [OrganizationPostalCode] => SimpleXMLElement Object
                        (
                        )
                    [IncludeForwardEmail] => NO
                    [ForwardEmailLinkText] => SimpleXMLElement Object
                        (
                        )

                    [IncludeSubscribeLink] => NO
                    [SubscribeLinkText] => SimpleXMLElement Object
                        (
                        )
                    [EmailContentFormat] => HTML
                    [EmailContent] => Some test content
                    [EmailTextContent] => SimpleXMLElement Object
                        (
                        )
                    [StyleSheet] => SimpleXMLElement Object
                        (
                        )
                    [ContactLists] => SimpleXMLElement Object
                        (
                        )
                    [FromEmail] => SimpleXMLElement Object
                        (
                            [Email] => SimpleXMLElement Object
                                (
                                    [@attributes] => Array
                                        (
                                            [id] => http://api.constantcontact.com
                                        )

                                    [link] => SimpleXMLElement Object
                                        (
                                            [@attributes] => Array
                                                (
                                                    [xmlns] => http://www.w3.org/2005/Atom
                                                    [href] => 
                                                    [rel] => self
                                                )
                                        )
                                )
                            [EmailAddress] => SimpleXMLElement Object
                                (
                                )
                        )
                    [ReplyToEmail] => SimpleXMLElement Object
                        (
                            [Email] => SimpleXMLElement Object
                                (
                                    [@attributes] => Array
                                        (
                                            [id] => http://api.constantcontact.com
                                        )

                                    [link] => SimpleXMLElement Object
                                        (
                                            [@attributes] => Array
                                                (
                                                    [xmlns] => http://www.w3.org/2005/Atom
                                                    [href] => 
                                                    [rel] => self
                                                )
                                        )
                                )
                            [EmailAddress] => SimpleXMLElement Object
                                (
                                )
                        )
                )
        )
    [source] => SimpleXMLElement Object
        (
            [id] => http://api.constantcontact.com/ws/customers/name/campaigns
            [title] => Campaigns for customer: name
            [link] => Array
                (
                    [0] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [href] => campaigns
                                )
                        )
                    [1] => SimpleXMLElement Object
                        (
                            [@attributes] => Array
                                (
                                    [href] => campaigns
                                    [rel] => self
                                )
                        )
                )
            [author] => SimpleXMLElement Object
                (
                    [name] => name
                )
            [updated] => 2011-10-14T17:28:31+01:00
        )
)

Am I missing some of the required parameters? Please advise.

 

Thank you

4 REPLIES 4
Highlighted
Employee

Re: Error 400 when adding a new campaign

Hey Gabrielag,

 

I know that you do not have to enter information for the id and link as they are set by the server.  I however do not think that is the issue.  If you would like you can try our new wrapper as I think it may be much simpler for you.

 

<?php
include 'wrapper/ConstantContact.php';

$ConstantContact = new ConstantContact("basic", "apikey", "username", "password");

$myCampaign = new Campaign();
$myCampaign->name = "The Name of my campaign";
$myCampaign->subject = "This is the subject of my campaign";
$myCampaign->emailContentFormat = "HTML";
$myCampaign->emailContent = "<html><body><h1>This is my HTML email</h1></body></html>";
$myCampaign->textVersionContent = "This is my TEXT email";

$VerifiedAddresses = $ConstantContact->getVerifiedAddresses();

$ConstantContact->addCampaign($myCampaign, $VerifiedAddresses[addresses][0]);

?>

 You can download the new wrapper here.

Ryan Davis
Quality Engineer
Highlighted
Occasional Contributor

Re: Error 400 when adding a new campaign

Thank you very much. It works with this new wrapper

Highlighted
Occasional Contributor

Re: Error 400 when adding a new campaign

Hi Ryan,
I am trying to get the campaign details as below and adding a new campaign with same details by just changing the name.
I am using:-      $thisCampaignDetails = $ConstantContact->getCampaignDetails($Campaign[$x]);  to get campaign details.

The response i am getting is  as follows: 

Campaign Object
(
    [name] => Testing Jan 04 2012
    [link] => /ws/customers/ {username} /campaigns/1109040673577
    [status] => Draft
    [campaignDate] => 2012-01-04T13:25:00.645Z
    [lastEditDate] => 2012-01-04T13:25:00.645Z
    [lastRunDate] => 
    [campaignSent] => 0
    [campaignOpens] => 0
    [campaignClicks] => 0
    [campaignBounces] => 0
    [campaignForwards] => 0
    [campaignOptOuts] => 
    [campaignSpamReports] => 
    [subject] => Create Excitement Event
    [fromName] => Create Excitement
    [campaignType] => STOCK
    [vawp] => YES
    [vawpLinkText] => 
    [vawpText] => Having trouble viewing this email?
    [permissionReminder] => YES
    [permissionReminderText] => 
    [greetingSalutation] => 
    [greetingName] => 
    [greetingString] => 
    [orgName] => Create Excitement
    [orgAddr1] => $ACCOUNT.ADDRESS_LINE_1
    [orgAddr2] => $ACCOUNT.ADDRESS_LINE_2
    [orgAddr3] => $ACCOUNT.ADDRESS_LINE_3
    [orgCity] => Madison
    [orgState] => WI
    [orgInternationalState] => 
    [orgCountry] => us
    [orgPostalCode] => 53711
    [incForwardEmail] => YES
    [forwardEmailLinkText] => Forward email
    [incSubscribeLink] => YES
    [subscribeLinkText] => Subscribe me!
    [emailContentFormat] => 
    [emailContent] => 
    [textVersionContent] => 
    [styleSheet] => 
    [lists] => Array
        (
            [0] => /ws/customers/ {username} /lists/18
        )
    [fromAddress] => VerifiedAddress Object
        (
            [email] => test@aol.com
            [status] => 
            [verifiedTime] => 
            [id] => 
            [link] => /ws/customers/ {username} /settings/emailaddresses/1
            [updated] => 
        )
    [replyAddress] => VerifiedAddress Object
        (
            [email] => test@aol.com
            [status] => 
            [verifiedTime] => 
            [id] => 
            [link] => /ws/customers/ {username} /settings/emailaddresses/1
            [updated] => 
        )
    [archiveStatus] => 
    [archiveUrl] => 
    [urls] => Array
        (
        )
)
I am missing the below details which are required.
    [greetingSalutation] => 
    [greetingName] => 
    [greetingString] => 
    [emailContentFormat] => 
    [emailContent] => 
    [textVersionContent] =>
So i am getting the below error:
Constant Contact Campaign Error: 'emailContentFormat' was required but not supplied
Constant Contact HTTP Request Exception: Error 400: Error: Line 1: cvc-pattern-valid: Value '' is not facet-valid with respect to pattern '((F|f)(I|i)(R|r)(S|s)(T|t)(N|n)(A|a)(M|m)(E|e))|((L|l)(A|a)(S|s)(T|t)(N|n)(A|a)(M|m)(E|e))|((F|f)(I|i)(R|r)(S|s)(T|t)(A|a)(N|n)(D|d)(L|l)(A|a)(S|s)(T|t)(N|n)(A|a)(M|m)(E|e))|((N|n)(O|o)(N|n)(E|e))' for type 'greetingchoices'. Error: Line 1: cvc-type.3.1.3: The value '' of element 'GreetingName' is not valid. Error: Line 1: cvc-pattern-valid: Value '' is not facet-valid with respect to pattern '((H|h)(T|t)(M|m)(L|l))|((X|x)(H|h)(T|t)(M|m)(L|l))' for type 'emailformat'. Error: Line 1: cvc-type.3.1.3: The value '' of element 'EmailContentFormat' is not valid. 

Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 1: parser error : Start tag expected, '<' not found in E:\wamp\www\campaign\constantcontact\scheduler\Collections.php on line 412

Warning: simplexml_load_string() [function.simplexml-load-string]: Error 400: Error: Line 1: cvc-pattern-valid: Value '' is not facet-valid with re in E:\wamp\www\campaign\constantcontact\scheduler\Collections.php on line 412

Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in E:\wamp\www\campaign\constantcontact\scheduler\Collections.php on line 412

Fatal error: Call to a member function Attributes() on a non-object in E:\wamp\www\campaign\constantcontact\scheduler\Components.php on line 547
Please help.
Thanks,
Harika
Highlighted
Employee

Re: Error 400 when adding a new campaign

Hey,

 

The reason for the issue is that you are trying to use one of our newsletter templates from our WYSIWYG editor. 

 

[campaignType] => STOCK

 

These emails are not editable or creatable via our API.  You would need to use Custom HTML emails in order to do that.

 

Please let me know if this helps.

Ryan Davis
Quality Engineer
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