OAuth V2/Refresh token Error

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

$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.)

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

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.

Hi, @amuro.

I’m glad to hear you resolved the issue!