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.