Attempting to obtain bearer token

I’m having trouble attaining a bearer token for a server to server app. Following instructions provided by Zoom for the Server to Server OAuth entry.

I use the following, inserting my ClientID, ClientSecret and AccountId in the respective places.

in powershell:

$creds = [System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(‘CLIENT_ID:CLIENT_SECRET’))

Invoke-WebRequest -Method POST -Uri https://zoom.us/oauth/token -ContentType ‘application/x-www-form-urlencoded’ -Body @{ grant_type=‘account_credentials’; account_id=‘ACCOUNT_ID’ } -Headers @{ Host=‘zoom. us’; Authorization=“Basic $creds” }

When I tried this I receive a generic 400 error that doesn’t get logged to the app

I also took the output of the $creds variable and used it for the command prompt options, as shown below.

in Command Prompt

curl -X POST https://zoom.us/oauth/token -d ‘grant_type=account_credentials’ -d ‘account_id={accountID}’ -H ‘Host: zoom. us’ -H ‘Authorization: Basic Base64Encoded(clientId:clientSecret)’

in this case I receive a “Bad host name error”.

I’ve gone through the FAQ, as well as verified that my app is server-to-server and it is active. I’m not sure what is missing here and could use some help.

As a note I had to add a space in the zoom .us to avoid the link limitation.

Hi @MP123 I generated a token on my end successfully using the following powershell and curl commands:

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Content-Type", "application/x-www-form-urlencoded")
$headers.Add("Authorization", "Basic $creds")
$body = "grant_type=account_credentials&account_id=..."
$response = Invoke-RestMethod 'https://zoom.us/oauth/token' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

curl --location 'https://zoom.us/oauth/token' --header 'Content-Type: application/x-www-form-urlencoded' --header 'Authorization: Basic ...' --data-urlencode 'grant_type=account_credentials' --data-urlencode 'account_id=...'

Can you reference these examples and try again?

Thank you for the response! Both should have worked. I ended up switching the process to a language I use more often and found the base64 encoding was giving me an unexpected conversion. The problem is solved.

1 Like