Issues with acccessing CC API v2 and migrating a PHP application from CC API v2 to CC API v3

CollinS62887
Rookie
0 Votes

Hi, 

 

I'm in the process of updating an application built using CakePHP v2.* that has been utilizing the v2 CC API (accessed through 'https://api.constantcontact.com/v2/) to access Email Campains. More specifically, the PHP application makes a GET call to the old API to grab the most recent Newsletter, here: https://sciencematters.tv/newsletters/current . The newsletter recently (in the past couple months) stopped populating. After looking at the response, it looks like the "link" the app receives is null, so nothing is displayed. The code used to find the latest newsletter is

 

....
$lastnewsletter = $this->find();
if($lastnewsletter != null){
   $apiKey = Configure::read('constant_contact_key');
   $token = Configure::read('constant_contact_token');
				
   $cc = new ConstantContact($apiKey);
   $campaign = $cc->getEmailCampaign($token, $lastnewsletter->id);
....

private function find($next = null){
   $apiKey = Configure::read('constant_contact_key');
   $token = Configure::read('constant_contact_token');
   $tmp = 'api key is '.$apiKey;
	
   $cc = new ConstantContact($apiKey);
   $params = array('limit'=>50, 'modified_since'=>date('2013-05-01'), 'status'=>'SENT');
   if($next != null){
      $params = array('next' => $next);
   }
   $results = $cc->getEmailCampaigns($token, $params);
   foreach($results->results as $result){
      if(isset($result->name) && strpos($result->name,'9287_newsletter') !== false){
         return $result;
      }
   }
   if($results->next != null){
      return $this->find($results->next);
   }	
}

 

the 'constant_contact-key' and 'constant-contact_token' are static. This doesn't seem to be how things work now. 

 

The goal is to move to the most recent version of the API (v3). So, I have two questions:

1) Are calls to the v2 API completely defunct? Is there any obvious reason the newsletter is no longer working? 

2) Since the process to access email compaigns looks like it changes with respect to the access token, are there any resources with PHP examples on what this process looks like? 

 

Thank you for any assistance. 

2 REPLIES 2
John__B
Employee
0 Votes

Hello CollinS62887,

 

Thank you for reaching out to Constant Contact API Developer Support. My team is here to assist outside software developers with questions about building into Constant Contact's API.

 

I’m sorry to hear that you’ve encountered issues while attempting to retrieve your most recent newsletters via the V2 API. To answer your questions, while the V2 endpoints are currently functional, we do plan to deprecate them and I would highly encourage you to migrate to V3 sooner rather than later. I’m glad to hear that you’ve already taken steps in this process.

 

Based on the code you provided, there isn’t an obvious reason that the webpage link in the response body would be null. If you’d like to further troubleshoot this V2 request, we would be happy to look into it if you could provide the full response examples along with the definitions for the “getEmailCampaign” & “getEmailCampaigns” functions in your code.

 

 We do have some short PHP examples in our documentation for V3 email endpoints which I’ll provide below.

 

Get Details for a Single Email Campaign:

https://v3.developer.constantcontact.com/api_guide/email_campaign_id.html

 

Get a Collection of Email Campaigns:

https://v3.developer.constantcontact.com/api_guide/email_campaigns_collection.html

 

Please have a look and let us know if you have any other questions!

 

Regards,


John B.
API Support Specialist
Did I answer your question? If so, please mark my post as an "Accepted Solution" by clicking the Accept as Solution button in the bottom right hand corner of this post.
WCCGoldenApple
Brand Strategist
0 Votes

CollinS62887, I would recommend using my PHP 8.0 API for CC V3.  Later this week I will be shipping a new client that is compatible with the new OAuth2 requirements, but the interface for you will not change.  Your code looks like it should be very easy to port.

 

You can find it here: https://packagist.org/packages/phpfui/constantcontact

Resources
Developer Portal

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

Visit Page

Announcements

API Updates

Join our list to be notified of new features and updates to our V3 API.

Sign Up