# BAD\_REFRESH\_TOKEN while trying to refresh token

**URL:** <https://community.hubspot.com/t/bad-refresh-token-while-trying-to-refresh-token/25304>\
**Category:** APIs & Integrations\
**Tags:** oauth\
**Created:** [September 10, 2020, 11:51am UTC](https://community.hubspot.com/t/bad-refresh-token-while-trying-to-refresh-token/25304 "2020-09-10T11:51:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mateuszg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mateuszg/32/1529_2.png) [@mateuszg](https://community.hubspot.com/u/mateuszg)\
**Post date:** [September 10, 2020, 11:51am UTC](https://community.hubspot.com/t/bad-refresh-token-while-trying-to-refresh-token/25304/1 "2020-09-10T11:51:05Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![himanshurauthan](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/himanshurauthan/32/53076_2.png) [@himanshurauthan](https://community.hubspot.com/u/himanshurauthan)\
**Post date:** [September 10, 2020, 1:13pm UTC](https://community.hubspot.com/t/bad-refresh-token-while-trying-to-refresh-token/25304/2 "2020-09-10T13:13:04Z")

</div>

Hey @mateuszg

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

Thanks!

---

<div class="post-metadata">

**Author:** ![mateuszg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mateuszg/32/1529_2.png) [@mateuszg](https://community.hubspot.com/u/mateuszg)\
**Post date:** [September 14, 2020, 7:27am UTC](https://community.hubspot.com/t/bad-refresh-token-while-trying-to-refresh-token/25304/3 "2020-09-14T07:27:56Z")

</div>

Hi @himanshurauthan :

```lia-code-sample
 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');
 }

```

---

<div class="post-metadata">

**Author:** ![mateuszg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mateuszg/32/1529_2.png) [@mateuszg](https://community.hubspot.com/u/mateuszg)\
**Post date:** [September 17, 2020, 12:31pm UTC](https://community.hubspot.com/t/bad-refresh-token-while-trying-to-refresh-token/25304/4 "2020-09-17T12:31:07Z")

</div>

Solved it. We were using access\_token instead of refresh token to refreshing

---

<div class="post-metadata">

**Author:** ![mukundrv](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/mukundrv/32/101739_2.png) [@mukundrv](https://community.hubspot.com/u/mukundrv)\
**Post date:** [September 29, 2020, 3:50pm UTC](https://community.hubspot.com/t/bad-refresh-token-while-trying-to-refresh-token/25304/5 "2020-09-29T15:50:20Z")

</div>

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
