upgrade from V2 to V3 api.

Regular Participant

upgrade from V2 to V3 api.

I am using V2 api to get all contacts. Below is the code:

$response = $cc->contactService->getContacts($params['token']);

Now I want to use V3 api. What change should I do in the above code.

I changed the base_url in config file as https://api.cc.email/v3/. 

And tired the above code, but nothing happened. 




Thank you for reaching out to Constant Contact API Developer Support.


Unfortunately our V2 PHP SDK is not going to work with our V3 API without significant changes. Our V3 API has a completely different schema and requirements. Your best option for using V3 is to manually make your calls.  

You can see what the call and response should look like by looking at the Response body and schema here: https://v3.developer.constantcontact.com/api_reference/index.html#!/Contacts/getContacts


You could create a function similar to the example code on our documentation page here: https://v3.developer.constantcontact.com/api_guide/contacts_subresources.html#example-get-request

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




David B.
Tier II API Support Engineer

Regular Participant

I see the example in PHP. I have some doubts

  1. Where should I provide the api-key/access token etc? Or where is config file?

  2. Where is HttpRequest  class? (since we are creating an object of the same)


In our V3 API, the API Key is not required to be included with your calls since we derive the API Key from the Access Token itself. The access token goes into the Authorization header the same way that it would in V2. From the code example linked above (just replace "{access_token}" with your access token):

  'cache-control' => 'no-cache',
  'authorization' => 'Bearer {access_token}',
  'content-type' => 'application/json',
  'accept' => 'application/json'

HttpRequest is often included with PHP, though you may need to enable it (https://stackoverflow.com/a/4565482). You are free to use any 3rd party http request library (such as Guzzle), or even cURL (https://stackoverflow.com/a/31318117) the same way you would for any other REST API.


David B.
Tier II API Support Engineer

Regular Participant

OK. I tried..but showing error:

Fatal error: Uncaught Error: Class 'HttpRequest' not found

What I tried is:

1. Downloaded php_http.dll from  http://originaldll.com/file/php_http.dll/19366.html
2. put the dll in D:\Xampp\php\ext
3. add extension = php_http.dll in php.ini
4. restart the system.

But the error is still there. How can I fix this? My php version is: 7.1.8



If you're having trouble using HttpRequest() you can use cURL instead. Here's an example:


// Define your access token
$access_token = "{YOUR_ACCESS_TOKEN}";

// Initialize a cURL object
$ch = curl_init();

// Define base URL
$base = 'https://api.cc.email/v3/';

// Create full request URL with chosen parameters
$url = $base . '/contacts?status=all&limit=500&include_count=true';
// Set the URL
curl_setopt($ch, CURLOPT_URL, $url);

// Set authorization header
$authorization = 'Authorization: Bearer ' . $access_token;
curl_setopt($ch, CURLOPT_HTTPHEADER, array($authorization));

// Set cURL to expect response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Make the call
$result = curl_exec($ch);

// Close cURL


See our V3 documentation for the types of parameters you can put onto the request URL here: https://v3.developer.constantcontact.com/api_reference/index.html#!/Contacts/getContacts

David B.
Tier II API Support Engineer

Regular Participant

While using the cURL for V3, I got the error as below:


string(59) "{"error_key":"unauthorized","error_message":"Unauthorized"}"


For the same access_token  V2 api is working.

Am I missing anything?


One more question..


Is V3 api is still in development? Or it is completely functioning. In some discussions I see that it is in development stage. 



Our V2 and V3 APIs do not share api keys or access tokens. You cannot use a V2 key and access token to make calls on our V3 API. I recommend starting in our Quick Start guide for V3 to get a feel for it: https://v3.developer.constantcontact.com/api_guide/getting_started.html


You can also use this page in our documentation on how to use OAuth in your application: https://v3.developer.constantcontact.com/api_guide/auth_overview.html


Our V3 API is full featured for contacts endpoints, and we have additional endpoints and features in development.



David B.
Tier II API Support Engineer

Regular Participant

Ok I understood. I go through the link  https://v3.developer.constantcontact.com/api_guide/getting_started.html

And I tested the call get contact using the link https://v3.developer.constantcontact.com/api_reference/index.html#!/Contacts/getContacts

It is working good.


But in the code we are using the access_token. How we generate the access token?

We can generate api key and secret while registering the application.

For V2 we can generate access token through https://constantcontact.mashery.com/io-docs

So for V3 how can I generate access_token?


Hi @DevL2,


The website https://constantcontact.mashery.com/io-docs was a test page that was intended to test the v2 API endpoints and in order to test those you needed an Access Token. When that page created and Access Token it also displayed the Access Token visibly which made an unintended use of people using the page to generate Access Tokens without creating their own oAuth flow.


With our v3 API we still have a page that is used to test the v3 API endpoints which is https://v3.developer.constantcontact.com/api_reference/index.html and it also creates and Access Token. However; for security reasons we no longer visibly display it.


You will want to go through the oAuth flow to create your own Access Token for use. https://v3.developer.constantcontact.com/api_guide/server_flow.html

Jimmy D.
Tier II API Support Engineer

so, can someone tell me how, or point me to documentation that allows an app to integrate with one constant contact account. we do not need to get permission to a users account, we simply need to create contacts in our account. This was simple in api 2 cause you just created a token and hard coded it. So, can I pass my account credentials problematically and get a token?

Hi @WalterW1,


Regardless of who owns the account you must get permission to access it. In our v2 API you granted that permission when you generated the Access Token and then you hardcoded it in your application. The only difference is that our v2 API Access Tokens had a default expiration time of 10 years.


The underlying process in the v3 API of granting access to the account is still required; this time the Access Tokens have a shorted expiration time for security purposes.


If you go back to the v2 API and generate a new Access Token (or read through the oAuth docs) you will notice the step to login to the Constant Contact account and click Allow.

Jimmy D.
Tier II API Support Engineer
Developer Portal

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

Visit Page