Unable to get access and refresh token with auth code

New Member


I am trying to connect my Hubspot App. 

We have received the auth code needed to exchange it for access and refresh token. However,  there was a problem with our server, so we couldn't send the request for the tokens in less than 10 minutes (which I've seen it's the expiration of the code), so we now get the following error:


"message":"auth code has expired".


How can we request a new auth code to be able to use our access and refresh tokens?

It doesn't work when we try agian through the URL form the first time : 





2 Replies 2
Regular Advisor | Silver Partner

Hi @Ejulia 


You'll need to use the Refresh Token to get a Current Token.


More info on OAuth.


What language are you developing in? If you are using PHP the Ryan Winchester Library will make life much easier:




Have fun


  1. Initiate an Integration with OAuth 2.0
  2. Get OAuth 2.0 Access Token and Refresh Tokens
  3. Refresh OAuth 2.0 Access Tokenken

In step 1, you need to send request to HS for auth request with your APP client ID, scopes and redirect URI. In response, a code will be returned.

In step 2, the previously obtained code has to be used for requesting access and refresh tokens. The code remain valids for few seconds and can not be reused.

$data = array(
'grant_type' => 'authorization_code',
'client_id' => $hapikey,
'client_secret' => $hseckey,
'code' => $_GET['code'],
'redirect_uri' => example.com,
$_GET['code'] is the code received in step1


As the HubSpot access token remains valid for 6 hours only so it is required to refresh the access token timely or better is to check with expiry timestamp of access token. For this, step 3 is needed.




Digital Marketing & Inbound Expert In Growth Hacking Technology