Server to server oauth "unsupported grant type"

Hi,

I’m trying to update our node.js app to use Server to server oauth. I have enabled Server-to-server OAuth app in role management. All the settings in in the Server to server oauth app seeem to be ok. The app is published.

This is the error I get: Error: Failed to generate access token: {“reason”:“unsupported grant type”,“error”:“unsupported_grant_type”}

Is the grant type supposed to be “account_credentials”? Can you please review my code. I have double checked that clientid,secret and accountid are correct.

Here is my code:

 private generateOauth(): Promise<string> {
   const clientID: string = "xxx";
   const clientSecret: string = "xxx";
   const accountID = "xxx";
 
   const authHeader = Buffer.from(`${clientID}:${clientSecret}`).toString('base64');
 
   const data = JSON.stringify({
     grant_type: 'account_credentials',
     account_id: accountID,
   });
 
   const options = {
     hostname: 'zoom.us',
     path: '/oauth/token',
     method: 'POST',
     headers: {
       'Content-Type': 'application/json',
       'Authorization': `Basic ${authHeader}`,
       'Content-Length': data.length,
     },
   };
 
   return new Promise((resolve, reject) => {
     const req = https.request(options, res => {
       let responseData = '';
 
       res.on('data', chunk => {
         responseData += chunk;
       });
 
       res.on('end', () => {
         if (res.statusCode === 200) {
           const response = JSON.parse(responseData);
           resolve(response.access_token);
         } else {
           reject(new Error(`Failed to generate access token: ${responseData}`));
         }
       });
     });
 
     req.on('error', error => {
       reject(error);
     });
 
     req.write(data);
     req.end();
   });
 }
1 Like

I get the same error when posting to /oauth/token from my python script. According the links below, setting the content type to “application/x-www-form-urlencoded” in the header might solve your problem. Wasn’t that simple for me, unfortunately, I’m still stuck.

The grant_type looks correct. I don’t think this endpoint accepts JSON (even though it responds with JSON); try formatting your request body as a query string and declaring the application/x-www-form-urlencoded content type instead. Our application sends this header: Content-Type: application/x-www-form-urlencoded; charset=utf-8

Thanks for your answers. Got it working by following your instructions.

1 Like

Your code looks correct, and you are using the correct grant type for Server-to-Server OAuth. Here are a few things to check:

  • Make sure that your Server-to-Server OAuth app is enabled and published.
  • Make sure that your client ID, client secret, and account ID are correct.
  • Make sure that you are using the correct Content-Type header: application/json.
  • Make sure that you are sending the request to the correct endpoint: https://zoom.us/oauth/token.

If you are still getting the same error, try using a different HTTP client library, such as Axios or Node-Fetch. You can also try using a different programming language, such as Python or Java, to see if you get the same error.

If you are still having trouble, please contact Zoom support for assistance.

Here is an example of how to use Axios to generate an access token using the Server-to-Server OAuth grant type:

const axios = require('axios');

async function generateOauth() {
  const clientID = 'YOUR_CLIENT_ID';
  const clientSecret = 'YOUR_CLIENT_SECRET';
  const accountID = 'YOUR_ACCOUNT_ID';

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

  const response = await axios.post('https://zoom.us/oauth/token', {
    grant_type: 'account_credentials',
    account_id: accountID,
  }, {
    headers: {
      'Authorization': `Basic ${authHeader}`,
      'Content-Type': 'application/json',
    },
  });

  if (response.status === 200) {
    return response.data.access_token;
  } else {
    throw new Error(`Failed to generate access token: ${response.statusText}`);
  }
}

const accessToken = await generateOauth();

// Use the access token to make API requests to Zoom

Hello,

It looks like you’re trying to obtain an access token using the “account_credentials” grant type for Server-to-Server OAuth with Zoom. The error you’re encountering, “unsupported_grant_type,” may be due to an incorrect grant type or a misconfiguration in your request.

In the Zoom API documentation, the grant type for Server-to-Server OAuth is typically “client_credentials” instead of “account_credentials.” Please try updating your grant_type to ‘client_credentials’ like this:

javascriptCopy code

const data = JSON.stringify({
  grant_type: 'client_credentials',
  // other parameters...
});

Make sure to check the Zoom API documentation for the correct grant type and any additional parameters required for your specific use case.

If the issue persists, double-check your client ID, client secret, and account ID to ensure they are correctly set. Additionally, you might want to verify if there are any specific configurations required for Server-to-Server OAuth in the Zoom Developer Dashboard.

Hope this helps!