# Getting intermittent 401 errors retrieving new access token

**URL:** <https://devforum.zoom.us/t/getting-intermittent-401-errors-retrieving-new-access-token/40806>\
**Category:** API and Webhooks\
**Created:** [January 17, 2021, 4:32pm UTC](https://devforum.zoom.us/t/getting-intermittent-401-errors-retrieving-new-access-token/40806 "2021-01-17T16:32:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg.ross](https://avatars.discourse-cdn.com/v4/letter/g/d9b06d/32.png) [@greg.ross](https://devforum.zoom.us/u/greg.ross)\
**Post date:** [January 17, 2021, 4:32pm UTC](https://devforum.zoom.us/t/getting-intermittent-401-errors-retrieving-new-access-token/40806/1 "2021-01-17T16:32:25Z")

</div>

**Description**  
Various users of our private OAuth app are getting intermittent errors when the app tries to retrieve a new access token using a stored refresh token.

**Error**  
Could not retrieve access token. Error: 401

PHP Code below.  
// $ID=client ID, $Scret = Client Secret, $rtoken = refresh token  
function newAccToken($ID, $Secret, $rtoken)

{

$b64idsec = base64\_encode($ID.":".$Secret);

$header = array(“Authorization: Basic {$b64idsec}”);

$curl = curl\_init();

$url = “[https://zoom.us/oauth/token](https://zoom.us/oauth/token)”;

$content=“grant\_type=refresh\_token&refresh\_token={$rtoken}”;  
curl\_setopt\_array($curl, array(

```
    CURLOPT_URL => $url,

    CURLOPT_SSL_VERIFYPEER => true,

    CURLOPT_RETURNTRANSFER => true,

    CURLOPT_POST => true,

    CURLOPT_POSTFIELDS => $content,

     CURLOPT_HTTPHEADER => $header

));

$response = curl_exec($curl);

$ret['response_code']=curl_getinfo($curl, CURLINFO_RESPONSE_CODE); // code > 200 error

$ret['response']=$response;

curl_close($curl);

return $ret;

```

}

---

<div class="post-metadata">

**Author:** ![MaxM](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/maxm/32/42303_2.png) [@MaxM](https://devforum.zoom.us/u/MaxM)\
**Post date:** [January 19, 2021, 6:25pm UTC](https://devforum.zoom.us/t/getting-intermittent-401-errors-retrieving-new-access-token/40806/2 "2021-01-19T18:25:13Z")

</div>

Hey @greg.ross,

Thank you for reaching out to the Zoom Developer Forum. First, It’s important to note that the refresh\_token will only work for the currently access\_token. If a new access\_token is requested separately then this will invalidate the refresh\_token that you have.

If that isn’t helpful, are you able to provide the full response body that you’re seeing when you encounter this issue?

Thanks,  
Max

---

<div class="post-metadata">

**Author:** ![greg.ross](https://avatars.discourse-cdn.com/v4/letter/g/d9b06d/32.png) [@greg.ross](https://devforum.zoom.us/u/greg.ross)\
**Post date:** [January 19, 2021, 7:05pm UTC](https://devforum.zoom.us/t/getting-intermittent-401-errors-retrieving-new-access-token/40806/3 "2021-01-19T19:05:30Z")

</div>

Thank you.  
I use the existing fresh token to get a new access token before using it and then save the new refresh token for another time. The same code works consistently for many api requests. I will change the code so it provides a full response body upon error.

---

<div class="post-metadata">

**Author:** ![MaxM](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/maxm/32/42303_2.png) [@MaxM](https://devforum.zoom.us/u/MaxM)\
**Post date:** [January 20, 2021, 6:50pm UTC](https://devforum.zoom.us/t/getting-intermittent-401-errors-retrieving-new-access-token/40806/4 "2021-01-20T18:50:11Z")

</div>

Hey @greg.ross,

Thank you for the update. I’ll advise further when we have the request body to review.

Thanks,  
Max

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/6/1/614bdd549b610bbaa46ff934617683a02bdaa03c.png) [@system](https://devforum.zoom.us/u/system)\
**Post date:** [February 20, 2021, 4:50am UTC](https://devforum.zoom.us/t/getting-intermittent-401-errors-retrieving-new-access-token/40806/5 "2021-02-20T04:50:34Z")

</div>

Closed on February 20, 2021, 4:50am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
