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

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):

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


    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) {

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

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

Can someone point out my mistake, please?

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.

That’s it, now it works - thanks!

    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);