Enter the Share Your Success Sweepstakes 2024 For the Chance to Win Great Prizes!

API v3 always gives "Unauthenticated error" message

PedroM202
Rookie

My company has an Email Plus account on Contact Contact.
We need to use Constant Contact API v3. I have followed the steps given in this article (https://v3.developer.constantcontact.com/api_guide/getting_started.html?_ga=2.29322108.1308822313.16... ) to register my application. 
Now, inside my PHP project, when I use the API Key and Secret (Generated through the steps given in the above article), I always get the "Unauthenticated error". 
I have tried to make calls to API with api_key as a query parameter and passing the access token in the header and also making a call to API without api_key as a query parameter.

None of the above worked and gave me the same unauthenticated error. I am using the following code :
       $token = "";
        $apiKey = "";
        
        $ch = curl_init();
        $headers = array();
        $headers[] = "Authorization: Bearer {$token}";
        $headers[] = 'Content-Type: application/json';
        $headers[] = 'Cache-Control: no-cache';
        $headers[] = 'Accept: application/json';
    
        // set URL and other appropriate options
        //curl_setopt($ch, CURLOPT_URL, "https://api.cc.email/v3/contacts?include_count=false?api_key=$api_key");
        curl_setopt($ch, CURLOPT_URL, "https://api.cc.email/v3/contacts");
        curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
        //curl_setopt($ch,CURLOPT_POSTFIELDS, $json_data);
           
        $curl_response = curl_exec($ch); 
        curl_close($ch); 
Am I doing anything wrong? Also, this access token is what I generated after registering the app
in the "My Application" section. Secondly, we have an Email Plus account instead of Developer's, is that
a problem?
 
2. Is there any way, where using the template IDs or any other identifier for the templates,  can I use the Templates for the emails through API? and can send variables to the template for example the Username or their email address or maybe a customized message?
1 REPLY 1
Courtney_E
Moderator
0 Votes

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.

It sounds like you’re off to the right start, and you shouldn’t need to make any changes to your account type. Now that you’ve generated your V3 API key and secret, you’ll need to complete the OAuth2 server flow in order to get an access token and refresh token so that your application can authenticate the connection to access the account.

Those steps can be found here:
https://v3.developer.constantcontact.com/api_guide/server_flow.html

For your second question, hopefully these answers will help clarify what can be done through the API:

Currently, only Custom Code emails can be created via the API, there’s not a way to access or edit standard templates the way that you would in the UI.
https://v3.developer.constantcontact.com/api_guide/email_campaign_create.html

If an email draft of the template already exists in the account and is set up with custom field variables, you could use the API to update the custom fields for the intended list of recipients to include a message and then schedule the email to a list through the API.
https://knowledgebase.constantcontact.com/articles/KnowledgeBase/6916-add-contact-details-using-the-...
.https://v3.developer.constantcontact.com/api_guide/create_custom_fields.html
https://v3.developer.constantcontact.com/api_guide/email_campaign_create_schedule.html


Regards,

Courtney E.
Tier II API Support Engineer

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.
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