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.

Server errors when trying to run SDK examples

SOLVED
Go to solution
Highlighted
Occasional Contributor

Server errors when trying to run SDK examples

Hi

When I try and run the create campaign and schedule example that come with the SDK i get this server error.

 

PHP Fatal error:  Uncaught exception 'Ctct\\Exceptions\\IllegalArgumentException' with message 'Only an id or ContactList object are allowed for this method.' in /var/www/html/eblast_sdk/src/Ctct/Components/EmailMarketing/Campaign.php:289\nStack trace:\n#0 /var/www/html/eblast_sdk/examples/createAndScheduleCampaign.php(63): Ctct\\Components\\EmailMarketing\\Campaign->addList(Array)\n#1 /var/www/html/eblast_sdk/examples/createAndScheduleCampaign.php(87): createCampaign(Array)\n#2 {main}\n  thrown in /var/www/html/eblast_sdk/src/Ctct/Components/EmailMarketing/Campaign.php on line 289, referer: http://www.ourtesturl.com/eblast_sdk/examples/createAndScheduleCampaign.php

 

(This is not the actual url)

 

Has anyone else run into this problem?

 

Cheers

Gary

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Employee

Re: Server errors when trying to run SDK examples

Hi,

 

I got the same error; we are looking into the sample campaign form code to see what the issue is, but in the meantime, if you don't mind building your own UI/form for creating and scheduling campaigns, you can use this more minimal create Campaign example as a jumping off point.  You may need to modify the required path, and you will need to modify the verified email addresses.

 

<?php

//Campaign create
require 'src/Ctct/autoload.php';

use Ctct\ConstantContact;
use Ctct\Exceptions\CtctException;
use Ctct\Components\EmailMarketing\Campaign;
use Ctct\Components\EmailMarketing\MessageFooter;

$apiKey = "value";
$accessToken = "value";

$cc = new ConstantContact($apiKey);

// message footer may be be required
$messageFooter = new MessageFooter();
$messageFooter->organization_name = "Constant Contact";
$messageFooter->address_line_1 = "1601 Trapelo Rd";
$messageFooter->city = "Waltham";
$messageFooter->country = "US";
$messageFooter->state = "MA";
$messageFooter->postal_code = "02451";

// campaign
$campaign = new Campaign();
$campaign->name = "my campaign 03252013";
$campaign->subject = "my subject";
$campaign->from_name = "John Doe";
$campaign->from_email = "verified_email@test.com";
$campaign->reply_to_email = "verified_email@test.com";
$campaign->text_content = "This is my text";
$campaign->email_content_format = "HTML";
$campaign->email_content = "<html><body>This is my content</body></html>";
$campaign->greeting_string = "Hello";
$campaign->message_footer = $messageFooter;

// attempt to add the campaign, dumping out the errors from any exceptions thrown
try {
    $response = $cc->addEmailCampaign($accessToken, $campaign);
    print_r($response);
} catch (CtctException $ex) {
    echo '<pre>';
    print_r($ex->getErrors());
    echo '</pre>';
}

?>

 

Sorry for the inconvenience!  We'll push the fixes to the current form to Github once the issue is resolved.

 

Best Regards,

Shannon W.

API Support Specialist

View solution in original post

5 REPLIES 5
Highlighted
Employee

Re: Server errors when trying to run SDK examples

Hi Gary,

 

On the form from the campaign example, are you seeing and selecting lists from your account before submitting the form?  The php error indicates that the sdk isn't getting the list in the account properly.

 

Best Regards,

Shannon W.

API Support Specialist

Highlighted
Occasional Contributor

Re: Server errors when trying to run SDK examples

Hi Shannon

 

Yes, I selected one of the available lists in list menu.

Highlighted
Employee

Re: Server errors when trying to run SDK examples

Hi,

 

I got the same error; we are looking into the sample campaign form code to see what the issue is, but in the meantime, if you don't mind building your own UI/form for creating and scheduling campaigns, you can use this more minimal create Campaign example as a jumping off point.  You may need to modify the required path, and you will need to modify the verified email addresses.

 

<?php

//Campaign create
require 'src/Ctct/autoload.php';

use Ctct\ConstantContact;
use Ctct\Exceptions\CtctException;
use Ctct\Components\EmailMarketing\Campaign;
use Ctct\Components\EmailMarketing\MessageFooter;

$apiKey = "value";
$accessToken = "value";

$cc = new ConstantContact($apiKey);

// message footer may be be required
$messageFooter = new MessageFooter();
$messageFooter->organization_name = "Constant Contact";
$messageFooter->address_line_1 = "1601 Trapelo Rd";
$messageFooter->city = "Waltham";
$messageFooter->country = "US";
$messageFooter->state = "MA";
$messageFooter->postal_code = "02451";

// campaign
$campaign = new Campaign();
$campaign->name = "my campaign 03252013";
$campaign->subject = "my subject";
$campaign->from_name = "John Doe";
$campaign->from_email = "verified_email@test.com";
$campaign->reply_to_email = "verified_email@test.com";
$campaign->text_content = "This is my text";
$campaign->email_content_format = "HTML";
$campaign->email_content = "<html><body>This is my content</body></html>";
$campaign->greeting_string = "Hello";
$campaign->message_footer = $messageFooter;

// attempt to add the campaign, dumping out the errors from any exceptions thrown
try {
    $response = $cc->addEmailCampaign($accessToken, $campaign);
    print_r($response);
} catch (CtctException $ex) {
    echo '<pre>';
    print_r($ex->getErrors());
    echo '</pre>';
}

?>

 

Sorry for the inconvenience!  We'll push the fixes to the current form to Github once the issue is resolved.

 

Best Regards,

Shannon W.

API Support Specialist

View solution in original post

Highlighted
Occasional Participant

Re: Server errors when trying to run SDK examples

Five months later i got the same error with the github examples, are you going to update it?

Highlighted
Occasional Participant

Re: Server errors when trying to run SDK examples

I think I fix it: on line 55 of createAndScheduleCampaign.php

 

replace:

 

$campaign->addList($params['lists']);

 

with:

 

$lista = $params['lists'];
$campaign->addList($lista[0]);

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