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

Hi @chunsiong.zoom I am trying with access token of creating a user it’s getting below error.

ruby code:
access_token=“eyJzdiI6IjAwMDAwMSIsImFsZyI6IkhTNTEyIiwidiI6IjIuMCIsImtpZCI6IjA3NjY1MzQ3LTI4Y2YtNDcyMC05OTYyLWMxNTcxMjQ0MjlhYiJ9.eyJ2ZXIiOjksImF1aWQiOiJkMmM3MDE3MmM3N2Y0MzhmYmMzMTE3MGIxMTUyYzk5OCIsImNvZGUiOiJudVVudld1WlpjeTJEQk41WjdHVHVXVU1NNm5DVWxQUEEiLCJpc3MiOiJ6bTpjaWQ6YVdQSDJKZmpUSVM1Z0V1djg1c0RyQSIsImdubyI6MCwidHlwZSI6MCwidGlkIjowLCJhdWQiOiJodHRwczovL29hdXRoLnpvb20udXMiLCJ1aWQiOiJ5QTg0RDJZV1FNLUFFM2VFV1paZ3B3IiwibmJmIjoxNzE4NzcxMTE5LCJleHAiOjE3MTg3NzQ3MTksImlhdCI6MTcxODc3MTExOSwiYWlkIjoiTTFxLVM2Rl9UR3VkaXB3aDFiejZ1USJ9.BuWBRB7kM7f8nesOPEVNwZ4PtyiW7qr9vYnR0vXGsWYwNzzrFrhyYAIRM9x_-ZbLcC9l3oDgXx5wMUWJnkwMxQ” # Make sure to replace this with your actual access token
zoom_create_user_url = ‘https://api.zoom.us/v2/users

user_info = {
  action: 'create',
  user_info: {
    email: 'user@example.com',
    type: 1,  # 1 is Basic, 2 is Licensed, 3 is On-prem
    first_name: 'John',
    last_name: 'Doe'
  }
}

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

request = Net::HTTP::Post.new(uri.request_uri, {
  'Authorization' => "Bearer #{access_token}",
  'Content-Type' => 'application/json'
})
request.body = user_info.to_json

response = http.request(request)

p JSON.parse(response.body)

end

error:
=> {“code”=>200, “message”=>“No privilege.”}

My zoom app name - General app 740
please help me resolve.

@anjibabuch987 did you add the create user scope for this oauth app?

yes @chunsiong.zoom I have added all below scopes for oauth app purpose but getting error
=> {“code”=>200, “message”=>“No privilege.”}

I have added this scopes:
“scope”=>“user:read:list_users:admin user:write:user:admin user:read:user:admin user:delete:user:admin user:update:password:admin user:read:list_assistants:admin user:delete:assistant:admin user:read:token:admin user:read:zak:admin user:delete:token:admin user:read:list_permissions:admin user:read:list_schedulers:admin user:delete:scheduler:admin user:update:email:admin user:read:email:admin user:read:pm_room:admin user:read:settings:admin user:delete:virtual_background_files:admin user:read:summary:admin user:read:list_collaboration_devices:admin user:read:collaboration_device:admin user:update:user_account:admin user:read:presence_status:admin user:read:personal_note:admin user:read:list_users:master user:write:user:master user:read:user:master user:update:user:master user:delete:user:master user:update:status:master user:update:password:master user:read:list_assistants:master user:write:assistant:master user:delete:assistant:master user:write:profile_picture:master user:read:token:master user:delete:token:master user:read:list_permissions:master user:read:list_schedulers:master user:delete:scheduler:master user:update:email:master user:update:presence_status:master user:read:settings:master user:update:settings:master user:write:virtual_background_files:master user:delete:virtual_background_files:master user:read:summary:master user:write:feature:master user:update:user_account:master user:read:presence_status:master user:read:personal_note:master”

please help me on this issue very urgent

@anjibabuch987 I’m not entirely sure whats wrong, but here’s a sample code in python for creating meeting. You can just change the json payload and the URL endpoint to create user.

      from flask import Flask, request
      import requests
      import json
      
      app = Flask(__name__)
      
      def handle_callapi():
          # Fetch access_token from query string
          access_token = request.args.get('access_token')
      
          # Meeting data
          meeting_data = {
              "topic": 'hello world',
              "type": 2,
              "start_time": "2023-10-01T10:00:00Z",
              "duration": 120,
              "password": "12345678",
              "agenda": "40 mins limit demonstration",
              "pre_schedule": False,
              "timezone": "Asia/Singapore",
              "default_password": False
          }
      
          # Zoom API endpoint
          api_url = 'https://api.zoom.us/v2/users/me/meetings'
      
          # Headers for the request
          headers = {
              "Authorization": f"Bearer {access_token}",
              "Content-Type": "application/json",
              "Accept": "application/json"
          }
      
          # Send POST request to create meeting
          response = requests.post(api_url, headers=headers, data=json.dumps(meeting_data))
      
          # Return response
          return "Meeting Details: " + response.text
      

Btw you are using the credentials in the development tab right?

Hi @chunsiong.zoom I have created same for user creation but it’s giving same error

code:

require 'base64'
require 'net/http'
require 'uri'
require 'json'

def handle_redirect_url_data_request(oauth_client_id, oauth_client_secret, code)
  url = "https://zoom.us/oauth/token"
  redirect_uri = "https://oauth.pstmn.io/v1/callback"

  credentials = "#{oauth_client_id}:#{oauth_client_secret}"
  credentials_encoded = Base64.strict_encode64(credentials)

  headers = {
    'Authorization' => "Basic #{credentials_encoded}",
    'Content-Type' => 'application/x-www-form-urlencoded'
  }

  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"
    response_json = JSON.parse(response.body)
    return response_json, 200 # Return JSON response with 200 status code
  else
    puts "Failed to obtain access token."
    puts "Response Code: #{response.code}"
    puts "Response Body: #{response.body}"
    return "Error: " + response.code, response.code.to_i
  end
end

def create_zoom_user(access_token)
  uri = URI.parse("https://api.zoom.us/v2/users")
  request = Net::HTTP::Post.new(uri)
  request.content_type = "application/json"
  request["Authorization"] = "Bearer #{access_token}"
  request.body = JSON.dump({
      action: 'create',
      user_info: {
        email: 'user@example.com',
        type: 1,  # 1 is Basic, 2 is Licensed, 3 is On-prem
        first_name: 'John',
        last_name: 'Doe'
      }
    })

  req_options = {
    use_ssl: uri.scheme == "https",
  }

  response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
    http.request(request)
  end

  if response.code == "201"
    puts "Meeting created successfully"
    puts response.body
  else
    puts "Failed to create meeting: #{response.code} #{response.message}"
    puts "Response body: #{response.body}"
  end
end

Replace these values with the correct ones

oauth_client_id = “aWPH2JfjTIS5gEuv85sDrA”
oauth_client_secret = “A0okV2mFTze6nkUxi7y2KmDf8jD8HVsd”
authorization_code = “DIjvaD65f2FVJLzbeaeT4CBs7tFUXkQdw”

token_response, status = handle_redirect_url_data_request(oauth_client_id, oauth_client_secret, authorization_code)

if status == 200
access_token = token_response[“access_token”]
puts “Access Token: #{access_token}”

Use the access token to create a Zoom meeting

create_zoom_user(access_token)
else
puts “Failed to obtain access token.”
end

error:
Failed to create meeting: 400 Bad Request
Response body: {“code”:200,“message”:“No privilege.”}
=> nil

NOTE - Create meetings are working fine your code but i need to create users

please help me on this issue.

Hi @chunsiong.zoom Please have a look help me on this issue it’s very urgent

@anjibabuch987

Sorry for the delay in response. If you need urgent help, I would strongly encourage you to look at paid developer support.

Please ensure that the authorization code is only used once. It is only valid once.

The current issue is that you have problem creating users?

Can you try with this payload?

{
“action”: “create”,
“user_info”: {
“email”: “tanchunsiong+msdk+test@gmail.com”,
“type”: 1,
“first_name”: “ChunSiong”,
“last_name”: “Tan”,
“password”: “P@ssw0rd223445”
}
}

HI @chunsiong.zoom I have tried your code but every time giving error only also i checked multiple times.

code:

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

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

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

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

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”
response_json = JSON.parse(response.body)
return response_json, 200 # Return JSON response with 200 status code
else
puts “Failed to obtain access token.”
puts “Response Code: #{response.code}”
puts “Response Body: #{response.body}”
return "Error: " + response.code, response.code.to_i
end
end

def create_zoom_user(access_token)
uri = URI.parse(“https://api.zoom.us/v2/users”)
request = Net::HTTP::Post.new(uri)
request.content_type = “application/json”
request[“Authorization”] = “Bearer #{access_token}”
request.body = JSON.dump({
action: “create”,
user_info: {
email: “tanchunsiong+msdk+test@gmail.com”,
type: 1,
first_name: “ChunSiong”,
last_name: “Tan”,
password: “P@ssw0rd223445”
}
})

req_options = {
use_ssl: uri.scheme == “https”,
}

response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
http.request(request)
end

if response.code == “201”
puts “User created successfully”
puts response.body
else
puts “Failed to create user: #{response.code} #{response.message}”
puts “Response body: #{response.body}”
if response.body.include?(‘No privilege’)
puts “The authenticated user does not have the required permissions.”
puts “Ensure the user has admin rights and the OAuth app has the user:write:admin scope.”
end
end
end

Replace these values with the correct ones

oauth_client_id = “aWPH2JfjTIS5gEuv85sDrA”
oauth_client_secret = “A0okV2mFTze6nkUxi7y2KmDf8jD8HVsd”
authorization_code = “8Im0r2asa47DYZoWln0QYeEOUIh8bqmJw”

token_response, status = handle_redirect_url_data_request(oauth_client_id, oauth_client_secret, authorization_code)

if status == 200
access_token = token_response[“access_token”]
puts “Access Token: #{access_token}”

Use the access token to create a Zoom user

create_zoom_user(access_token)
else
puts “Failed to obtain access token.”
end

=====
Error:
Failed to create user: 400 Bad Request
Response body: {“code”:200,“message”:“No privilege.”}
The authenticated user does not have the required permissions.
Ensure the user has admin rights and the OAuth app has the user:write:admin scope.
=> nil

also I have added this scopes:

Meeting

meeting:write:meeting:master, meeting:write:meeting:admin

User

user:update:user:master, user:update:user_account:admin, user:delete:token:master, user:write:user:master, user:update:password:admin, user:read:summary:master, user:read:user:master, user:delete:assistant:admin, user:delete:scheduler:master, user:read:list_users:admin, user:update:settings:master, user:delete:scheduler:admin, user:delete:user:admin, user:read:list_users:master, user:read:personal_note:admin, user:read:settings:master, user:update:presence_status:master, user:read:list_permissions:admin, user:read:presence_status:master, user:read:list_schedulers:master, user:read:presence_status:admin, user:read:list_assistants:master, user:read:list_schedulers:admin, user:read:personal_note:master, user:read:list_permissions:master, user:read:pm_room:admin, user:write:virtual_background_files:master, user:delete:virtual_background_files:admin, user:read:list_collaboration_devices:admin, user:read:collaboration_device:admin, user:delete:assistant:master, user:read:zak:admin, user:update:user_account:master, user:update:password:master, user:read:token:admin, user:update:email:master, user:write:assistant:master, user:write:profile_picture:master, user:delete:token:admin, user:read:token:master, user:read:settings:admin, user:read:user:admin, user:read:email:admin, user:update:status:master, user:read:list_assistants:admin, user:update:email:admin, user:delete:user:master, user:delete:virtual_background_files:master, user:write:feature:master, user:read:summary:admin, user:write:user:admin, user:update:presence_status:admin, user:write:feature:admin, user:update:status:admin, user:write:virtual_background_files:admin, user:update:settings:admin, user:write:profile_picture:admin, user:write:assistant:admin, user:update:user:admin, user:delete:profile_picture:admin

Contact center

contact_center:delete:inbox_user:admin, contact_center:write:inbox_user:admin, contact_center:update:batch_users:admin, contact_center:update:user:admin, contact_center:write:batch_users:admin, contact_center:delete:user:admin, contact_center:write:user:admin, contact_center:delete:batch_users:admin, contact_center:read:list_skill_users:admin, contact_center:read:user_deleted:admin, contact_center:read:list_user_queues:admin, contact_center:read:list_users:admin, contact_center:read:inbox_user:admin, contact_center:read:skill_user:admin, contact_center:read:user_updated:admin, contact_center:read:user:admin

Team Chat

team_chat:delete:member:admin, team_chat:write:message_files:admin, team_chat:read:channel:admin, team_chat:read:list_invitations:admin, team_chat:update:message_emoji:admin, team_chat:read:list_administrators:admin, team_chat:read:user_channel:admin, team_chat:update:user_message:admin, team_chat:read:list_user_sessions:admin, team_chat:read:list_user_messages:admin, team_chat:write:administrator:admin, team_chat:write:user_channel:admin, team_chat:read:list_channels:admin, team_chat:write:members:admin, team_chat:delete:user_channel:admin, team_chat:read:list_user_channels:admin, team_chat:write:files:admin, team_chat:read:list_bookmarks:admin, team_chat:delete:user_message:admin, team_chat:read:list_members:admin, team_chat:read:chat_control:admin, team_chat:update:user_channel:admin, team_chat:read:user_message:admin, team_chat:update:message_status:admin, team_chat:delete:batch_administrators:admin, team_chat:read:message_emoji:admin, team_chat:write:user_message:admin

please check and help me on this issue.
I need to create the users.

@anjibabuch987 do you have this scope?