# Failed to refresh tokens: {response.status\_code} {response.text}

**URL:** <https://devforum.zoom.us/t/failed-to-refresh-tokens-response-status-code-response-text/113308>\
**Category:** Authentication\
**Tags:** api\
**Created:** [July 9, 2024, 12:58pm UTC](https://devforum.zoom.us/t/failed-to-refresh-tokens-response-status-code-response-text/113308 "2024-07-09T12:58:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![vtrinh](https://avatars.discourse-cdn.com/v4/letter/v/3d9bf3/32.png) [@vtrinh](https://devforum.zoom.us/u/vtrinh)\
**Post date:** [July 9, 2024, 12:58pm UTC](https://devforum.zoom.us/t/failed-to-refresh-tokens-response-status-code-response-text/113308/1 "2024-07-09T12:58:49Z")

</div>

**Description**  
I’m not able to access the token through pyzoom. It was working perfectly fine before so I’m a bit confused. I checked the client ID and secret to see if they changed, but they didn’t. I even tried making a new app, but it didn’t work either.

**Error**  
The error message I’m getting is `Failed to refresh tokens: {response.status_code} {response.text}`

**How To Reproduce**

1. Create a connection to Zoom’s API through pyzoom.

```auto
import os
from pyzoom import oauth_wizard, ZoomClient

client = ZoomClient(oauth_wizard(os.getenv('CLIENT_ID'), os.getenv('CLIENT_SECRET'))["access_token"])

```

1. It’ll redirect you to the redirect URI. Press “Allow”.
2. Error message pops up.

---

<div class="post-metadata">

**Author:** ![gianni.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/gianni.zoom/32/32523_2.png) [@gianni.zoom](https://devforum.zoom.us/u/gianni.zoom)\
**Post date:** [July 9, 2024, 3:31pm UTC](https://devforum.zoom.us/t/failed-to-refresh-tokens-response-status-code-response-text/113308/2 "2024-07-09T15:31:20Z")

</div>

Hi @vtrinh , pyzoom is not a Zoom created product. [On the disclaimer description](https://pypi.org/project/pyzoom/) it says “This library is not related to Zoom Video Communications, Inc. It’s an open-source project that aims to simplify working with this suddenly very popular service.” Please reach out to the creators for support.

If other community members see this and have familiarity, they are more than inclined to assist further here 🙂

---

<div class="post-metadata">

**Author:** ![vtrinh](https://avatars.discourse-cdn.com/v4/letter/v/3d9bf3/32.png) [@vtrinh](https://devforum.zoom.us/u/vtrinh)\
**Post date:** [July 10, 2024, 1:33pm UTC](https://devforum.zoom.us/t/failed-to-refresh-tokens-response-status-code-response-text/113308/4 "2024-07-10T13:33:55Z")

</div>

I rewrote my code to not include the pyzoom module to see if that was the issue, but I’m still getting an error.

`{'reason': 'Invalid Grant', 'error': 'invalid_grant'}`

This is my new code:

```auto
from requests import post
from base64 import b64encode
import http.server
import webbrowser

CLIENT_ID = "insert client id"
CLIENT_SECRET = "insert client secret"

PORT = 3000
REDIRECT_URI = f"http://localhost:{PORT}"

class ReqHandle(http.server.SimpleHTTPRequestHandler):
    def do_GET(self) -> None:
        self.send_response(200)
        self.server.auth_code = self.path.split("/?code=")[1] # ugly

webbrowser.open(f"https://zoom.us/oauth/authorize?response_type=code&client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}")

server = http.server.HTTPServer(("", PORT), ReqHandle)
server.handle_request()

auth_code = server.auth_code

headers = {
    "Content-Type": "application/x-www-form-urlencoded",
    "Authorization": "Basic " + b64encode(f"{CLIENT_ID}:{CLIENT_SECRET}".encode()).decode()
}

data = {
    "code": auth_code,
    "redirect_uri": REDIRECT_URI,
    "grant_type": "authorization_code",
}

r = post("https://zoom.us/oauth/token", headers=headers, data=data)
print(r.json())

```

---

<div class="post-metadata">

**Author:** ![gianni.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/gianni.zoom/32/32523_2.png) [@gianni.zoom](https://devforum.zoom.us/u/gianni.zoom)\
**Post date:** [July 12, 2024, 3:46pm UTC](https://devforum.zoom.us/t/failed-to-refresh-tokens-response-status-code-response-text/113308/5 "2024-07-12T15:46:08Z")

</div>

Hi @vtrinh , I see authorization and an attempt for an access token. Check out the sample code for refresh token on our Postman workspace: [Postman](https://www.postman.com/zoom-developer/workspace/zoom-public-workspace/request/22097587-a975098f-214b-4265-8315-a5a0bb4e9d09?tab=headers&ctx=code)

 ![image](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/a/c/acf39480e272a1c0ee483f09fc2aa27a5c254a54.png)

---

<div class="post-metadata">

**Author:** ![vtrinh](https://avatars.discourse-cdn.com/v4/letter/v/3d9bf3/32.png) [@vtrinh](https://devforum.zoom.us/u/vtrinh)\
**Post date:** [July 15, 2024, 3:08am UTC](https://devforum.zoom.us/t/failed-to-refresh-tokens-response-status-code-response-text/113308/6 "2024-07-15T03:08:50Z")

</div>

From what I understand, the refresh token request requires an access token as part of the request body. Unfortunately, due to the nature of our setup, since we were in rapid testing we would request and immediately discard access tokens after one use. This means I do not have an access token from any previous attempts that I could potentially refresh.

---

<div class="post-metadata">

**Author:** ![gianni.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/gianni.zoom/32/32523_2.png) [@gianni.zoom](https://devforum.zoom.us/u/gianni.zoom)\
**Post date:** [July 15, 2024, 7:42pm UTC](https://devforum.zoom.us/t/failed-to-refresh-tokens-response-status-code-response-text/113308/7 "2024-07-15T19:42:05Z")

</div>

@vtrinh ,

> [@vtrinh](#):
>
> From what I understand, the refresh token request requires an access token as part of the request body. Unfortunately, due to the nature of our setup, since we were in rapid testing we would request and immediately discard access tokens after one use. This means I do not have an access token from any previous attempts that I could potentially refresh.

You should be caching your _refresh token_ supplied with the access token, and use the refresh token to refresh access token. Refresh tokens expire after 90 days. Please see the guidance here: [OAuth for user authorized apps](https://developers.zoom.us/docs/integrations/oauth/#refreshing-an-access-token)

Additionally, you do not need to re-auth each time you request an access token or refresh an access token.

---

<div class="post-metadata">

**Author:** ![vtrinh](https://avatars.discourse-cdn.com/v4/letter/v/3d9bf3/32.png) [@vtrinh](https://devforum.zoom.us/u/vtrinh)\
**Post date:** [July 15, 2024, 8:59pm UTC](https://devforum.zoom.us/t/failed-to-refresh-tokens-response-status-code-response-text/113308/8 "2024-07-15T20:59:11Z")

</div>

Thank you for the follow up. Our original problem is still there: we cannot authorize any new tokens, and have no tokens to attempt a refresh on since we did not cache the refresh token before. The same error applies: “invalid grant”. Are there any other tips you can provide that would help with this immediate issue?

---

<div class="post-metadata">

**Author:** ![gianni.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/gianni.zoom/32/32523_2.png) [@gianni.zoom](https://devforum.zoom.us/u/gianni.zoom)\
**Post date:** [July 16, 2024, 7:38pm UTC](https://devforum.zoom.us/t/failed-to-refresh-tokens-response-status-code-response-text/113308/9 "2024-07-16T19:38:20Z")

</div>

Hi @vtrinh , please try your conditions in the sample environment via postman from the link I shared. I am able to successfully grab a token. Click “overview” to see the documentation. If you’re able to generate a token in Postman, it’s like your code that needs to be reconfigured.
