Unable to get access and refresh token with auth code

New Member

Hi!

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:

"status":"EXPIRED_AUTH_CODE",

"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 : 

https://app.hubspot.com/oauth/authorize?client_id=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&scope=contacts%20automation&redirect_uri=https://www.example.com/

Thanks! 

Eli 

 

Reply
0 Upvotes
2 Replies 2
Highlighted
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:

 

https://github.com/ryanwinchester/hubspot-php

 

Have fun

Mike

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

Thanks.

 

 

Digital Marketing & Inbound Expert In Growth Hacking Technology