Reg: Need help in creating users through oauth v2 API

Hi Team,

Good Morning…!,

We are trying to integrate zoom API with oauth v2 to creating users in zoom with access token.

Error:

{
“error”: “This API does not support client credentials for authorization.”
}

My Zoom account: anjibabuch987@gmail.com

Step: 1 Created app and enabled oauth2 , scopes(admin create user).

Step2: Generated access token with client credentials.

Code:
uri = URI(‘https://zoom.us/oauth/token’)
params = { grant_type: ‘client_credentials’, client_id: “”, client_secret: “” }
response = Net::HTTP.post(uri, URI.encode_www_form(params))
data = JSON.parse(response.body)

Step3: With access token trying to create user(url: ) it’s getting above error.

Code:
uri = URI(‘https://api.zoom.us/v2/users’)
request = Net::HTTP::Post.new(uri)
request.content_type = ‘application/json’
request[‘Authorization’] = “Bearer #{access_token}”
request.body = {
action: ‘create’,
user_info: {
email: user_params[:email],
type: user_params[:type],
first_name: user_params[:first_name],
last_name: user_params[:last_name],
password: user_params[:password]
}
}.to_json

  response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
    http.request(request)
  end
  JSON.parse(response.body)

Can you please help us to resolve this issue.

Please let me know if you need any information my side.

Thanks
Anjibabu Ch

@anjibabuch987 what programming language are you using?

@chunsiong.zoom ruby on rails I am a back end developer

Hi @chunsiong.zoom It’s very urgent please help me on this issue

@anjibabuch987 I don’t have sample code in RoR, but did you try this out on Postman btw?

@chunsiong.zoom Yes tried but every time getting access token issue.
{
“error”: “This API does not support client credentials for authorization.”
}

@anjibabuch987

the closest i have are python based sample

here’s how to use get access token using OAuth

    from flask import Flask, request, jsonify
        import base64
        import requests
        import urllib.parse  # Import the urllib module for URL encoding
        
        def handle_redirect_url_data_request(path, oauth_client_id, oauth_client_secret, code):
            print ("handle_redirect_url_data_request")
            url = f"https://zoom.us/oauth/token"
            redirect_uri=f"https://python.asdc.cc/{path}"
            print (redirect_uri)
            
            # Encode the client ID and client secret
            credentials = f"{oauth_client_id}:{oauth_client_secret}"
            credentials_encoded = base64.b64encode(credentials.encode()).decode('utf-8')
        
            headers = {
                'Authorization': f'Basic {credentials_encoded}',
                'Content-Type': 'application/x-www-form-urlencoded',
               
            }
            print (credentials_encoded)
        
            data = {
                'grant_type': 'authorization_code',
                'redirect_uri': redirect_uri,
                'code': code
            }
            # Encode the data dictionary as x-www-form-urlencoded
            data_encoded = urllib.parse.urlencode(data).encode('utf-8')
        
        
            response = requests.post(url, data=data_encoded, headers=headers)
            # Check the HTTP status code before parsing as JSON
            if response.status_code == 200:
               print ("response 200")
               response_json = response.json()
               print(response_json)
               return response_json, 200  # Return JSON response with 200 status code
            else:
                
                # Handle the case where the response has an error status code
                return "Error: " + str(response.status_code), response.status_code
        

@chunsiong.zoom I have converted to ruby code what you have given python code.

require ‘base64’
require ‘net/http’
require ‘uri’
require ‘json’

def handle_redirect_url_data_request(path, oauth_client_id, oauth_client_secret, code)
puts “handle_redirect_url_data_request”
url = “https://zoom.us/oauth/token
redirect_uri = “Python Sample code for Zoom Meeting SDK, Zoom OAuth App, Webhooks and REST API
puts redirect_uri
oauth_client_id = “aWPH2JfjTIS5gEuv85sDrA”
oauth_client_secret = “A0okV2mFTze6nkUxi7y2KmDf8jD8HVsd”

credentials = “#{oauth_client_id}:#{oauth_client_secret}”
credentials_encoded = Base64.encode64(credentials).strip

headers = {
‘Authorization’ => “Basic #{credentials_encoded}”,
‘Content-Type’ => ‘application/x-www-form-urlencoded’
}

puts credentials_encoded

data = {
‘grant_type’ => ‘authorization_code’,
‘redirect_uri’ => redirect_uri,
‘code’ => code
}

data_encoded = URI.encode_www_form(data)

uri = URI(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Post.new(uri.path, headers)
request.body = data_encoded

response = http.request(request)

if response.code == “200”
puts “response 200”
response_json = JSON.parse(response.body)
puts response_json
return response_json, 200 # Return JSON response with 200 status code
else
return "Error: " + response.code, response.code.to_i

end
end
handle_redirect_url_data_request(“/”, “aWPH2JfjTIS5gEuv85sDrA”, “A0okV2mFTze6nkUxi7y2KmDf8jD8HVsd”, “15Z4khKkwTdEgSFScKcTuK3Vd67ZpBgkw”)

getting this error please help me
handle_redirect_url_data_request(“/”, “aWPH2JfjTIS5gEuv85sDrA”, “A0okV2mFTze6nkUxi7y2KmDf8jD8HVsd”, “15Z4khKkwTdEgSFScKcTuK3Vd67ZpBgkw”)
handle_redirect_url_data_request
https://python.asdc.cc//
YVdQSDJKZmpUSVM1Z0V1djg1c0RyQTpBMG9rVjJtRlR6ZTZua1V4aTd5Mktt
RGY4akQ4SFZzZA==
Traceback (most recent call last):
3: from (irb):111
2: from (irb):96:in handle_redirect_url_data_request' 1: from (irb):96:in new’
ArgumentError (header Authorization has field value “Basic YVdQSDJKZmpUSVM1Z0V1djg1c0RyQTpBMG9rVjJtRlR6ZTZua1V4aTd5Mktt\nRGY4akQ4SFZzZA==”, this cannot include CR/LF)

@anjibabuch987 you are using my redirect URL, it will not work. You have to use your own redirect URL.

And how did you convert this btw?

@chunsiong.zoom I have used on my URL which is configured for application but it still same error.

require ‘base64’
require ‘net/http’
require ‘uri’
require ‘json’

def handle_redirect_url_data_request(path, oauth_client_id, oauth_client_secret, code)
puts “handle_redirect_url_data_request”
url = “https://zoom.us/oauth/token
redirect_uri = “https://oauth.pstmn.io/v1/callback
puts redirect_uri
oauth_client_id = “aWPH2JfjTIS5gEuv85sDrA”
oauth_client_secret = “A0okV2mFTze6nkUxi7y2KmDf8jD8HVsd”

credentials = “#{oauth_client_id}:#{oauth_client_secret}”
credentials_encoded = Base64.encode64(credentials).strip

headers = {
‘Authorization’ => “Basic #{credentials_encoded}”,
‘Content-Type’ => ‘application/x-www-form-urlencoded’
}

puts credentials_encoded

data = {
‘grant_type’ => ‘authorization_code’,
‘redirect_uri’ => redirect_uri,
‘code’ => code
}

data_encoded = URI.encode_www_form(data)

uri = URI(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true

request = Net::HTTP::Post.new(uri.path, headers)
request.body = data_encoded

response = http.request(request)

if response.code == “200”
puts “response 200”
response_json = JSON.parse(response.body)
puts response_json
return response_json, 200 # Return JSON response with 200 status code
else
return "Error: " + response.code, response.code.to_i

end
end
handle_redirect_url_data_request(“/”, “irb(main):204:0> handle_redirect_url_data_request(”/", “aWPH2JfjTIS5gEuv85sDrA”, “A0okV2mFTze6nkUxi7y2KmDf8jD8HVsd”, “15Z4khKkwTdEgSFScKcTuK3Vd67ZpBgkw”)
handle_redirect_url_data_request
https://oauth.pstmn.io/v1/callback
YVdQSDJKZmpUSVM1Z0V1djg1c0RyQTpBMG9rVjJtRlR6ZTZua1V4aTd5Mktt
RGY4akQ4SFZzZA==
Traceback (most recent call last):
3: from (irb):204
2: from (irb):189:in handle_redirect_url_data_request' 1: from (irb):189:in new’
ArgumentError (header Authorization has field value “Basic YVdQSDJKZmpUSVM1Z0V1djg1c0RyQTpBMG9rVjJtRlR6ZTZua1V4aTd5Mktt\nRGY4akQ4SFZzZA==”, this cannot include CR/LF)
", “A0okV2mFTze6nkUxi7y2KmDf8jD8HVsd”, “15Z4khKkwTdEgSFScKcTuK3Vd67ZpBgkw”)

getting error:

Please help me on this issue.
I Know python and ruby i done the coding.

@anjibabuch987 for hygiene coding purpose, could you check if the quotes are all in " and not “”

I’m not exactly sure why there is complain about line feed / carrier, it might be a quote thing