cancel
Showing results for 
Search instead for 
Did you mean: 

More PHP samples for Constant Contact SDK v2

Occasional Advisor

More PHP samples for Constant Contact SDK v2

I've downloaded PHP examples for the SDK Version 2 from this link:

https://github.com/constantcontact/php-sdk/tree/development/examples

 

I was wondering if there might be more extensive samples for getting all lists, retreiving all campaigns, delete list, delete campaign, etc, similar to this link, which I think is for the API v1:

https://github.com/integrationservices/Constant-Contact-PHP-Developers-Code/tree/master/examples

6 REPLIES 6
Honored Contributor

Re: More PHP samples for Constant Contact SDK v2

Hello,

 

This is a great questions, and I unfortunately have to say that we don't currently have extra samples pre-built for the V2 PHP SDK. However, there are a couple things that can make developing easier!

 

  1. You can look at the service classes in the SDK directly to see a list of their methods and a description. Example: https://github.com/constantcontact/php-sdk/blob/development/src/Ctct/Services/ContactService.php
  2. If you are looking for an example of a specific action, I could likely also craft a snippet of code to demonstrate how it could be done.

 

If you have any questions or feedback, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer

Re: More PHP samples for Constant Contact SDK v2

Thanks for your reply!  I'd like to build an application that gives the user an option to send a test campaign so will likely use the 'sendTest' function in the CampaignScheduleService class.

 

I've been able to build an application that simply creates and sends a campaign, but we'd like to send a test campaign first, and if we do that, is that test campaign automatically stored in the constant contact account as a draft?

 

And once the test campaign is sent, and if it's stored as a draft, I would like to give the user the opportunity send that draft as an actual campaign via the 'createSchedule' function in the CampaignScheduleService class.  That part I have been able to do, so I think it's the creating and sending a draft first that I need help with - any examples or suggestions would be greatly appreciated.

Occasional Advisor

Re: More PHP samples for Constant Contact SDK v2

FYI, that last response was from me signed into a different account 'PortofHoodRiver', who I am building the application for - sorry about the confusion.

Honored Contributor

Re: More PHP samples for Constant Contact SDK v2

Not a problem!

 

The process for sending a test campaign with our system involves creating a campaign object and then sending that to Constant Contact to create a draft status campaign. Once the campaign has been created (using the addCampaign method of the EmailMarketingService), you can then make use of the testSend() method of the CampaignScheduleService. Here's a quick code sample to demonstrate how this can be done:

 

$campaign = $emailService->addCampaign($token, $campaignToBeCreated);
$testSend = TestSend::create(array("format"=>"HTML", "email_addresses"=>array("email1@example.com","email2@example.com")));

$scheduleService->sendTest($token, $campaign->id, $testSend);

Additionally, you can read about the limits and restrictions on test sending at the documentation page for this endpoint here: http://developer.constantcontact.com/docs/email-testsend/email-campaign-testsend-api.html

 

EDIT: I wanted to add that once a draft campaign has been created and a test has been sent, you can then schedule that same campaign after making any modifications that come up when reviewing the test.

 

If you have any questions, please let me know!

 

Sincerely,

Elijah G.
API Support Engineer
Occasional Visitor

Re: More PHP samples for Constant Contact SDK v2

The addCampaign() function is throwing a bad request.  There doesn't appear to be any way to enable debugginng in the ConstantContact PHP API.  I'd like to see an example of how to construct an instance of $campaignToBeCreated which will pass muster with the API.  The API key and access token are correct; other calls are working with them.

Moderator

Re: More PHP samples for Constant Contact SDK v2

Hello,

 

Thank you for reaching out to the API Support team here at Constant Contact.

 

There isn't a method specfically for debuggin in our PHP Wrapper. Any time one of the services runs into an error, it throws a CtctException that contains the the response message (bad request, etc), response code, and any errors JSON formatted in the response body. Your best option is to include code to catch these exceptions so you can see the contents of these errors.

 

Please let me know if you have any other questions.

Sincerely,
David B.
API Support Specialist