HOW TO

Create a new user with a custom role using ArcGIS API for Python

Last Published: February 9, 2023

Summary

New members can be added to ArcGIS Server when required. For example, if a new member joins the organization, they can be assigned custom roles according to the organization's requirements. To add new members and roles, administrators must access ArcGIS Server Manager. Refer to ArcGIS Server: Manage users in Manager for more information.

Alternatively, ArcGIS API for Python can be used because it allows administrators to add new members with custom roles without accessing ArcGIS Server Manager. This article provides the workflow.

Procedure

  1. Import the necessary modules.
from arcgis import GIS
  1. Specify the credentials to connect to the portal.
gis = GIS("https://<machine>.<domain>.com/<web apdaptor name>", "username", "password")

print(' server: ' + gis.properties.name)
print(' server: ' + gis.properties.username)
print(' server: ' + gis.properties.role)
  1. List the current roles in the organization and store the desired roles in a variable.
gis.users.roles.all(max_roles=50)
roles = gis.users.roles.all(max_roles=50)
  1. Print the role name and ID. The role ID is required when creating a new user with a custom role.
print(roles[2].name)
print(roles[2].role_id)
  1. Create the new user with the custom role.
gis.users.create(username='username',
                 password='password',
                 firstname = 'Peter',
                 lastname='Parker',
                 email='PParker@test.com',
                 description='Test user',
                 role='sadc65er16c1e5f',
                 user_type='Creator')

The code block below demonstrates the full script.

from arcgis import GIS
gis = GIS("https://test.esri.com/arcgis", "username", "password")

print(' server: ' + gis.properties.name)
print(' server: ' + gis.properties.username)
print(' server: ' + gis.properties.role)

gis.users.roles.all(max_roles=50)
roles = gis.users.roles.all(max_roles=50)

print(roles[2].name)
print(roles[2].role_id)

gis.users.create(username='username',
                 password='password',
                 firstname = 'Peter',
                 lastname='Parker',
                 email='PParker@test.com',
                 description='Test user',
                 role=roles[2].role_id,
                 user_type='Creator')

Article ID:000023404

Software:
  • Portal for ArcGIS
  • ArcGIS API for Python 1 x

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic