# (Server-to-Server OAuth) Can't get the Access Token

**URL:** <https://devforum.zoom.us/t/server-to-server-oauth-cant-get-the-access-token/76381>\
**Category:** API and Webhooks\
**Created:** [September 22, 2022, 11:11am UTC](https://devforum.zoom.us/t/server-to-server-oauth-cant-get-the-access-token/76381 "2022-09-22T11:11:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ygallist](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/ygallist/32/41642_2.png) [@ygallist](https://devforum.zoom.us/u/ygallist)\
**Post date:** [September 22, 2022, 11:11am UTC](https://devforum.zoom.us/t/server-to-server-oauth-cant-get-the-access-token/76381/1 "2022-09-22T11:11:06Z")

</div>

Hey there,

I’m a beginner Programmer and can’t figure out, why I can’t get the Access Token - it always fails with the Base64 encryption. Here is the code (Node.js / VS Code):

```auto
const clientID = Buffer.from(process.env.ZOOM_ID).toString('base64');
 const clientSecret = Buffer.from(process.env.ZOOM_S_CLIENT).toString('base64');

    console.log(clientID);
    console.log(clientSecret);

    var http = new XMLHttpRequest();
    var url = 'https://zoom.us/oauth/token?grant_type=account_credentials&account_id=MYACCOUNTID'; //(I replaced the ID with the text, in my code there is the Account ID)
    http.open('POST', url, true);

    http.setRequestHeader("Content-Type", "application/json");
    http.setRequestHeader('Authorization', 'Basic ' + clientID + ':' + clientSecret);

    http.onreadystatechange = function() {
        if(http.readyState == 4 && http.status == 200) {
            console.log(http.responseText);
        }
    }
    http.send();

```

I log the ID and secret for testing purpose, and they are encrypted. But I always get the error message:

```auto
{
  "status": false,
  "errorCode": -1,
  "errorMessage": "Input byte array has incorrect ending byte at 32",
  "result": null
}

```

Can someone point out my mistake, please?

---

<div class="post-metadata">

**Author:** ![MultiplayerSession](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/multiplayersession/32/66446_2.png) [@MultiplayerSession](https://devforum.zoom.us/u/MultiplayerSession)\
**Post date:** [September 22, 2022, 1:48pm UTC](https://devforum.zoom.us/t/server-to-server-oauth-cant-get-the-access-token/76381/2 "2022-09-22T13:48:34Z")

</div>

For the authorization header value, you’ll need to concatenate the client ID, the literal colon, and the client secret first, then base 64 encode the concatenated result. Currently, you’re individually base 64 encoding the client ID and client secret, then concatenating them.

---

<div class="post-metadata">

**Author:** ![ygallist](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/ygallist/32/41642_2.png) [@ygallist](https://devforum.zoom.us/u/ygallist)\
**Post date:** [September 23, 2022, 12:59am UTC](https://devforum.zoom.us/t/server-to-server-oauth-cant-get-the-access-token/76381/3 "2022-09-23T00:59:50Z")

</div>

That’s it, now it works - thanks!

```auto
    const clientID = process.env.ZOOM_ID;
    const clientSecret = process.env.ZOOM_S_CLIENT;

    const authentication = Buffer.from(`${clientID}:${clientSecret}`).toString('base64');

    http.setRequestHeader('Authorization', 'Basic ' + authentication);

```

---

<div class="post-metadata">

**Author:** ![donte.zoom](https://sea2.discourse-cdn.com/flex016/user_avatar/devforum.zoom.us/donte.zoom/32/24412_2.png) [@donte.zoom](https://devforum.zoom.us/u/donte.zoom)\
**Post date:** [September 29, 2022, 9:27pm UTC](https://devforum.zoom.us/t/server-to-server-oauth-cant-get-the-access-token/76381/4 "2022-09-29T21:27:40Z")

</div>

Thanks for sharing your insight @MultiplayerSession ! For other interested community members, please see our OAuth with Zoom support documentation for more details:

# OAuth with Zoom

[https://marketplace.zoom.us/docs/guides/auth/oauth/](https://marketplace.zoom.us/docs/guides/auth/oauth/)

 ![Screen Shot 2022-09-29 at 5.25.22 PM](https://us1.discourse-cdn.com/flex016/uploads/zoomdeveloper/original/3X/2/8/2882c7f2bffa63a8ceb06733cfebeed41fa7df6c.png)

---

<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:** [October 3, 2023, 1:04pm UTC](https://devforum.zoom.us/t/server-to-server-oauth-cant-get-the-access-token/76381/5 "2023-10-03T13:04:07Z")

</div>

Closed on October 3, 2023, 1:04pm UTC

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