HOW TO

Enable Esri Access for all members of an ArcGIS Online organization

Last Published: April 25, 2020

Summary

As of July 2016, all users with an Esri-enabled ArcGIS Online organizational account have access to self-paced e-learning classes. To allow members to access these courses, organizational administrators may be interested in enabling Esri access for all users.

Procedure

Esri Access can be enabled for each individual user in the organization by clicking the options gear next to their username on the My Organization page. In addition, batch enabling is possible outside of the interface programmatically, using Python and the REST API. A sample script is provided below.

To run the script:
  1. Copy the script below into a Python 2.7 integrated development environment (IDE).
  2. Run the script. No modification to the script is required.
  3. When asked, provide the username and password of an organization administrator.
     
    #import system modules
    import urllib
    import urllib2
    import json
    from pprint import pprint
    
    #Define functions
    def get_total_users(token, url_Key):
        """
        Returns the total number of user's in an organization.
        """
        max_Url = 'http://{0}.maps.arcgis.com/sharing/rest/portals/self/users?f=json&token={1}'.format(
            url_Key, token
        )
        response = make_request(max_Url)
        return response['total']
    
    
    def get_token(user, pw):
        """
        Returns a token used to make user-specific requests.
        """
        params = {
            'f': 'json',
            'password': pw,
            'referer' : 'https://www.arcgis.com',
            'username': user,
        }
        url = 'https://arcgis.com/sharing/rest/generateToken'
        json_Response = make_request(url, params)
        return json_Response['token']
    
    
    def get_url_key(token):
        """
        Returns the Url Key used
        """
        URL= 'http://www.arcgis.com/sharing/rest/portals/self?f=json&token=' + token
        response = make_request(URL)
        url_Key = response['urlKey']
        return url_Key
    
    
    def get_user_list(token, url_Key, total_Users):
        """
        Returns a list of all users in an organization.
        """
        start = 1
        number = 100
        user_List = list()
        while start-1 < total_Users:
            list_URL ='http://{0}.maps.arcgis.com/sharing/rest/portals/self/users?start={1}&num={2}&f=json&token={3}'.format(
                url_Key,
                str(start),
                str(number),
                token
            )
            response = make_request(list_URL)
            for item in response['users']:
                user_List.append(item['username'])
            start += number
        return user_List
    
    
    def make_request(url, params=None):
        """
        Handles all requests made via the REST API.
        """
        if params:
            response = urllib2.urlopen(url, urllib.urlencode(params)).read()
        else:
            response = urllib2.urlopen(url).read()
        return json.loads(response)
    
    
    def update_myesri_access(user, url_Key, token):
        """
        Updates MyEsri access for a single user.
        """
        userURL ='https://{0}.maps.arcgis.com/sharing/rest/community/users/{1}/update'.format(
            url_Key, user
        )
        params = {
            'f':'json',
            'token':token,
            'usertype':'both'
        }
        response = make_request(userURL, params)
    
    #Main function
    if __name__ == "__main__":
        """
        Prompts user for a username and password, generates a list of all users
        in an organization, then enables MyEsri access for all users.
        """
        user = raw_input("Admin username: ")
        password = raw_input("Password: ")
    
        token = get_token(user, password)
        url_Key = get_url_key(token)
    
        total_Users = get_total_users(token, url_Key)
        all_Users = get_user_list(token, url_Key, total_Users)
    
        print("User List:")
        pprint(sorted(all_Users))
        print("Enabling Esri Access")
    
        for user in all_Users:
            update_myesri_access(user, url_Key, token)
    
        print("Esri Access enabled")
Another sample script can be found here, but does require installation of the ArcREST module.
Note:
As these are script samples, Esri Support does not debug specific scenarios of the script failing or assist in customizing it further.

Article ID:000014653

Software:
  • ArcGIS Online

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic