BAD_REFRESH_TOKEN while trying to refresh token

SOLVE
mateuszg
Participant

Hey: 

 

I am trying to refresh a token, but unfortunately, I receive status 400 with:

{
"status": "BAD_REFRESH_TOKEN",
"message": "missing or invalid refresh token",
"correlationId": "13aa419f-f7c7-4f2a-85e3-cd837c669576"
}
 
In request I send following params:
refreh_token: TOKEN
client_secret: ID
client_id: SECRET
grant_type:refresh_token
 
I have header set to: application/x-www-form-urlencoded;charset=utf-8
How can I successfully refresh a token?
0 Upvotes
1 Accepted solution

Accepted Solutions
mateuszg
Solution
Participant

Solved it. We were using access_token instead of refresh token to refreshing

View solution in original post

0 Upvotes
4 Replies 4
himanshurauthan
Key Advisor | Platinum Partner

Hey @mateuszg 

 

Can you please post the post request script that you have written for the refreshing the access token?

 

Thanks!

Digital Marketing & Inbound Expert In Growth Hacking Technology
mateuszg
Participant

 

Hi @himanshurauthan :

 let refreshTokenResult;

  const requestBody = {
    grant_type: 'refresh_token',
    client_id: clientId,
    client_secret: clientSecret,
    refresh_token: account.remoteConnection.hubspot.accessToken,
  };

  try {
    refreshTokenResult = await rp({
      method: 'post',
      url: 'https://api.hubapi.com/oauth/v1/token',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
      },
      body: querystring.stringify(requestBody),
    });
  } catch (error) {
    global.logger.error(error);
    throw new Error('Cannot refresh HubSpot access token');
  }

 

0 Upvotes
mateuszg
Solution
Participant

Solved it. We were using access_token instead of refresh token to refreshing

View solution in original post

0 Upvotes
mukundrv
Member

I just figured out that if there are any new line or invalid characters in the refresh token it gives the error message BAD_REFRESH_TOKEN

0 Upvotes