Getting error during server Oauth 2.0 exchange authorization code for an access token

christianh3714
Rookie
0 Votes

Using cURL, I am able to get the authorization code.  However when then using cURL to try to exchange for an access token, I get an error: Client authentication (if the client has credentials) or the client_id parameter is required for an authorization request using the code grant type.  Not sure what I am doing wrong.  Any suggestions?

3 REPLIES 3
Courtney_E
Moderator
0 Votes

Hello Christian,

 

The steps to Exchange the Authorization Code for an Access Token and a Refresh Token can be found on the OAuth2.0 Server Flow page under Step 4:
https://v3.developer.constantcontact.com/api_guide/server_flow.html


Please note that this request requires the string “client_id:client_secret” to be encoded using Base 64.


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.
MrRoyo
Campaign Contributor
0 Votes

Hello Courtney E

 

I am getting the same issue. I am able to get the authorization code using curl. But when I try to exchange authorization code with access token it gives me error "Bad message 400, reason: Unkown version". I am using the same code provided in the Server Flow guide:

 

function getAccessToken($redirectURI, $clientId, $clientSecret, $code) {
// Use cURL to get access token and refresh token
$ch = curl_init();

// Define base URL
$base = 'https://idfed.constantcontact.com/as/token.oauth2';

// Create full request URL
$url = $base . '?code=' . $code . '&redirect_uri=' . $redirectURI . '&grant_type=authorization_code&scope=contact_data';
curl_setopt($ch, CURLOPT_URL, $url);

// Set authorization header
// Make string of "API_KEY:SECRET"
$auth = $clientId . ':' . $clientSecret;
// Base64 encode it
$credentials = base64_encode($auth);
// Create and set the Authorization header to use the encoded credentials
$authorization = 'Authorization: Basic ' . $credentials;
curl_setopt($ch, CURLOPT_HTTPHEADER, array($authorization));

// Set method and to expect response
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

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

Courtney_E
Moderator
0 Votes

Hello MrRoyo,

 

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

 

It looks like we're working with you directly via email regarding your inquiry, but I wanted to close the loop here as well. If you haven't received our reply, please let us know via email at webservices@constantcontact.com, and reference case number 28232085.


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