Device Flow Refresh Token

0 Votes
Hi, I'm following the 6/6/2023 reply from John__B; and wrote this refresh token function in PHP; function refreshToken($refreshToken, $clientId, $connection) { $ch = curl_init(); // Define endpoint URL $url = ''; // Set up the POST fields $postData = [ 'refresh_token' => $refreshToken, 'grant_type' => 'refresh_token', 'client_id' => $clientId ]; curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); // Set other cURL options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded')); // Execute and return the response $result = curl_exec($ch); if (curl_errno($ch)) { return 'Error:' . curl_error($ch); } curl_close($ch); $responseData = json_decode($result, true); // Convert the JSON string to an associative array $accessToken = $responseData['access_token']; // Get the access_token value setAuthToken($connection, $accessToken); return $accessToken; } and it returns "The refresh token is invalid or expired". When I get my original token, I receive; {"token_type":"Bearer","expires_in":86400,"access_token":"","scope":"openid contact_data","id_token":"}. Is the refresh token the "id_token"? Is my function correct and I'm receiving the refresh token invalid because I waited too long to refresh my token? Thank you in advance for your help. Best Regards, Brian
0 Votes

Hello HelpingHandsAct,


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.


Based on what you are experiencing, it looks like the refresh token is most likely not being stored correctly as a variable within the application.


If you continue to run into issues, could you please contact us directly/securely via email  at (do not post sensitive info in the community) and provide us with the API key that you are using to make the request, the full request(s) where you are receiving the response (including URL, headers, timestamp, and request body), and the full response body so that we can better assist you in identifying the root cause of the issue?


While our expertise is with our API itself as opposed to its implementation within any particular programming language, we are happy to answer any questions pertaining to Constant Contact’s API endpoints, functionality, and documentation.


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


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

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

Visit Page


API Updates

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

Sign Up