# OAuth V2/Refresh token Error

**URL:** <https://community.hubspot.com/t/oauth-v2-refresh-token-error/13319>\
**Category:** APIs & Integrations\
**Tags:** oauth\
**Created:** [March 4, 2019, 6:14am UTC](https://community.hubspot.com/t/oauth-v2-refresh-token-error/13319 "2019-03-04T06:14:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![amuro](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/amuro/32/89259_2.png) [@amuro](https://community.hubspot.com/u/amuro)\
**Post date:** [March 4, 2019, 6:14am UTC](https://community.hubspot.com/t/oauth-v2-refresh-token-error/13319/1 "2019-03-04T06:14:49Z")

</div>

Hi

When trying to update the access token, the following response is returned from the API.

- {“status”:“BAD\_REFRESH\_TOKEN”,“message”:“missing or invalid refresh token”,“correlationId”:“xxxx”,“requestId”:“xxxxx”}

- 
  - Why does this problem happen?

- My PHP code

```auto
$url = "https://api.hubapi.com/oauth/v1/token";
$argary = array(
'grant_type' => 'refresh_token',
'client_id' => 'XXXXXXXX',
'client_secret' => 'XXXXXXXX',
'redirect_uri' => 'https://XXXXX/OAuth/auth-callback',
'refresh_token'=> '--My first refresh token--'

);
$query_string = http_build_query($argary, "", "&");
$options = array (
'http' => array (
'method' => 'POST',
'header' => 'Content-Type: application/x-www-form-urlencoded;charset=utf-8',
'content' => $query_string,
'ignore_errors' => true,
'protocol_version' => '1.1'
),
'ssl' => array (
//'allow_self_signed' => true,
'verify_peer' => false,
'verify_peer_name' => false
)
);
$contents = @file_get_contents($url, false, stream_context_create($options));
echo $contents;
exit();

```

- 
  - (I’m sorry, I am not so good at English.)

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [March 4, 2019, 8:55pm UTC](https://community.hubspot.com/t/oauth-v2-refresh-token-error/13319/2 "2019-03-04T20:55:00Z")

</div>

Welcome, @amuro.

Happy to help, however I’m not spotting any issues with your PHP code. The `BAD_REFRESH_TOKEN` response almost always indicates that the refresh token is either malformed or is no longer available for use (e.g. if the app was disconnected and reconnected).

What do you receive if you call [this endppoint](https://developers.hubspot.com/docs/methods/oauth2/get-refresh-token-information) with your refresh token value?

- If the endpoint returns information about the token, please direct message me the results.
- If the endpoint cites an error, then the refresh token is no longer valid.

---

<div class="post-metadata">

**Author:** ![amuro](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/amuro/32/89259_2.png) [@amuro](https://community.hubspot.com/u/amuro)\
**Post date:** [March 5, 2019, 12:26am UTC](https://community.hubspot.com/t/oauth-v2-refresh-token-error/13319/3 "2019-03-05T00:26:52Z")

</div>

Hi @IsaacTakushi

Thank you for your prompt reply.  
I was able to solve this problem on my own.  
RefreshTOKEN I set was old.

Thank you very much for giving me many advice.

---

<div class="post-metadata">

**Author:** ![IsaacTakushi](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/isaactakushi/32/70387_2.png) [@IsaacTakushi](https://community.hubspot.com/u/IsaacTakushi)\
**Post date:** [March 5, 2019, 1:12pm UTC](https://community.hubspot.com/t/oauth-v2-refresh-token-error/13319/4 "2019-03-05T13:12:35Z")

</div>

Hi, @amuro.

I’m glad to hear you resolved the issue!
