# Requesting an access token using a refresh token "reason":"Invalid Token!","error":"invalid\_grant"

**URL:** <https://devforum.zoom.us/t/requesting-an-access-token-using-a-refresh-token-reason-invalid-token-error-invalid-grant/96884>\
**Category:** Authentication\
**Created:** [October 17, 2023, 3:32am UTC](https://devforum.zoom.us/t/requesting-an-access-token-using-a-refresh-token-reason-invalid-token-error-invalid-grant/96884 "2023-10-17T03:32:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![customers](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@customers](https://devforum.zoom.us/u/customers)\
**Post date:** [October 17, 2023, 3:32am UTC](https://devforum.zoom.us/t/requesting-an-access-token-using-a-refresh-token-reason-invalid-token-error-invalid-grant/96884/1 "2023-10-17T03:32:11Z")

</div>

For the past week or possibly even before, we have been encountering an error when attempting to request an access token using a refresh token.

The error message we receive is as follows:  
{“reason”:“Invalid Token!”,“error”:“invalid\_grant”}

We’re currently uncertain as to when exactly this error began occurring.

As a temporary workaround, we are asking our users to reauthorize our app. While this seems to resolve the issue for the time being, it’s imperative for us to understand the root cause of this problem to ensure it doesn’t persist or recur.

We would greatly appreciate any insights or assistance you can provide regarding this matter.

* * *

**API Endpoint(s) and/or Zoom API Event(s)**  
[https://zoom.us/oauth/token](https://zoom.us/oauth/token)

**Error**  
{“reason”:“Invalid Token!”,“error”:“invalid\_grant”}

---

<div class="post-metadata">

**Author:** ![chunsiong.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/chunsiong.zoom/32/35488_2.png) [@chunsiong.zoom](https://devforum.zoom.us/u/chunsiong.zoom)\
**Post date:** [October 17, 2023, 4:52am UTC](https://devforum.zoom.us/t/requesting-an-access-token-using-a-refresh-token-reason-invalid-token-error-invalid-grant/96884/2 "2023-10-17T04:52:06Z")

</div>

@customers ,

do you have the code snippet on how you are getting the access token using your refresh token?

---

<div class="post-metadata">

**Author:** ![customers](https://avatars.discourse-cdn.com/v4/letter/c/df705f/32.png) [@customers](https://devforum.zoom.us/u/customers)\
**Post date:** [October 17, 2023, 8:58am UTC](https://devforum.zoom.us/t/requesting-an-access-token-using-a-refresh-token-reason-invalid-token-error-invalid-grant/96884/3 "2023-10-17T08:58:41Z")

</div>

@chunsiong.zoom ,

Thank you for your response.

Here is the code:  
PHP

```auto
// get access token with the refresh token
$basic = base64_encode($Client_ID . ':' . $Client_Secret);

$headers = array(
  "Authorization: Basic $basic",
  "Content-Type: application/x-www-form-urlencoded"
);

$body = array(
  'grant_type' => 'refresh_token',
  'refresh_token' => $REFRESH_TOKEN // use stored refresh token.
);

$curl = curl_init("https://zoom.us/oauth/token");

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($body));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_ENCODING, "");
curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

$arr = json_decode($response, true);
$access_token = $arr['access_token'];

if ($access_token == '') {
  http_response_code(400);
  echo json_encode(["message" => "Error: $response"]); // Error: {"reason":"Invalid Token!","error":"invalid_grant"}
}

```

---

<div class="post-metadata">

**Author:** ![chunsiong.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/chunsiong.zoom/32/35488_2.png) [@chunsiong.zoom](https://devforum.zoom.us/u/chunsiong.zoom)\
**Post date:** [October 18, 2023, 3:10am UTC](https://devforum.zoom.us/t/requesting-an-access-token-using-a-refresh-token-reason-invalid-token-error-invalid-grant/96884/4 "2023-10-18T03:10:02Z")

</div>

@customers ,

I’ve just written this sample, and testing it to be working. There are some slight variations.

```auto

$url = 'https://zoom.us/oauth/token';

// Encode the client ID and client secret
$basic = base64_encode($Client_ID . ':' . $Client_Secret);

$headers = [
    "Authorization: Basic $basic",
    "Content-Type: application/x-www-form-urlencoded"
];

$data = [
    'grant_type' => 'refresh_token',
    'refresh_token' => $refreshToken,
];

// Encode the data dictionary as x-www-form-urlencoded
$dataEncoded = http_build_query($data);

$options = [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_HTTPHEADER => $headers,
    CURLOPT_POSTFIELDS => $dataEncoded,
];

$ch = curl_init();
curl_setopt_array($ch, $options);

$response = curl_exec($ch);
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);

curl_close($ch);

if (strpos($httpStatus, '200') !== false) {
    $responseJson = json_decode($response, true);
    http_response_code(200);
    header('Content-Type: application/json');
    echo json_encode($responseJson);
    //echo $response;
} else {
    echo "$httpStatus\n";
}

```
