Learn how to sign in and access your portal programmatically using an access token.
Prerequisites
You need an ArcGIS Location Platform, ArcGIS Online, or ArcGIS Enterprise account to use your portal.
Steps
Get the portal URL
To access a portal, you need an ArcGIS account which is associated with an organization that allows you to store and manage your content.
- In a web browser, sign in to your portal with your ArcGIS account.
- Identify the portal URL from the navigation bar. The base URL should be one of the following:
- ArcGIS Location Platform:
https:
//www.arcgis.com/sharing/rest - ArcGIS Online:
https:
//www.arcgis.com/sharing/rest - ArcGIS Enterprise:
https:
//{machine.domain.com}/{webadaptor}/rest
- ArcGIS Location Platform:
- Copy the URL and store it in a safe location. You will need it in a later step.
Get an access token
To perform the portal service operation in this tutorial, you need an access token from OAuth 2.0 credentials. It is the only supported form of authentication. The use of API keys is not supported.
-
Go to the Create OAuth credentials for user authentication tutorial to get a set of OAuth 2.0 credentials.
-
Get an access token from the OAuth 2.0 credentials.
-
Copy the access token to your clipboard when prompted.
Set up environment
- In a different window, launch Postman and create a blank request.
- Install the ArcGIS API for Python.
- Start your Jupyter Notebook environment locally.
- To get started, .
Perform a self
call
- Set the request type to
POST
. - Paste your portal URL and append
/self
at the end. - Set the
f
parameter tojson
in the parameter list. - Set the
token
parameter to your access token in the parameter list. - Run the request.
POST arcgis.com/sharing/rest/portals/self HTTP/1.1
Content-Type: application/x-www-form-urlencoded
&f=json
&token=<YOUR_ACCESS_TOKEN>
-
Add the following
import
statements to your code.main.pyUse dark colors for code blocks import requests import json
-
Create a variable
url
and paste in your portal URL, appending/self
at the end.main.pyUse dark colors for code blocks import requests import json url = "https://www.arcgis.com/sharing/rest/portals/self"
-
Set the following parameters and paste in your access token in the appropriate field.
main.pyUse dark colors for code blocks import requests import json url = "https://www.arcgis.com/sharing/rest/portals/self" params = { "f": "json", "token": "YOUR_ACCESS_TOKEN", }
-
Execute the REST call and print the
JSON
response.main.pyUse dark colors for code blocks import requests import json url = "https://www.arcgis.com/sharing/rest/portals/self" params = { "f": "json", "token": "YOUR_ACCESS_TOKEN", } response = requests.get(url, params=params) if response.status_code == 200: # Print the JSON response print(json.dumps(response.json(), indent=4)) else: print("Failed to retrieve self info. Status code:", response.status_code)
-
Create a request block in your code using
esri/request
library.Use dark colors for code blocks require(["esri/request"], (esriRequest)=> { });
-
Create a variable
url
and paste in your portal URL, appending/self
at the end.Use dark colors for code blocks require(["esri/request"], (esriRequest)=> { const url = "https://www.arcgis.com/sharing/rest/portals/self" });
-
Set the following parameters in an
options
object and paste in your access token in the appropriate field.Use dark colors for code blocks require(["esri/request"], (esriRequest)=> { const url = "https://www.arcgis.com/sharing/rest/portals/self" const options = { query: { f: "pjson", token: "YOUR_ACCESS_TOKEN" }, responseType: "pjson" }; });
-
Execute the REST call and print the
JSON
response.Use dark colors for code blocks require(["esri/request"], (esriRequest)=> { const url = "https://www.arcgis.com/sharing/rest/portals/self" const options = { query: { f: "pjson", token: "YOUR_ACCESS_TOKEN" }, responseType: "pjson" }; esriRequest(url, options,{ }).then((response)=>{ const data = response.data console.log(data); }) });
View the results
The output of your self
call should look something like this, but with information about your portal:
{
"2DStylesGroupQuery": "title:\"Esri 2D Styles\" AND owner:esri_en",
"3DBasemapGalleryGroupQuery": "title:\"ArcGIS Online 3D Basemaps\" AND owner:esri_en",
"access": "public",
"allSSL": true,
"allowedRedirectUris": [],
"analysisLayersGroupQuery": "title:\"Living Atlas Analysis Layers\" AND owner:esri",
"authorizedCrossOriginDomains": [],
"availableCredits": 5.0018196E7,
"basemapGalleryGroupQuery": "title:\"United States Basemaps\" AND owner:Esri_cy_US",
"canListApps": false,
"canListConsultingServices": false,
- To get started, .
What's next
![](/documentation/static/access-feature-layer-data-fe6f3f2d53d5ce5d3207e3b43c9c6c59.png)
Copy a hosted layer item
Use the portal service to copy a hosted layer item in your portal.
![](/documentation/static/access-feature-layer-data-fe6f3f2d53d5ce5d3207e3b43c9c6c59.png)
Set sharing level for an item
Use the portal service to set the sharing level for an item in your portal.
![](/documentation/static/access-feature-layer-data-fe6f3f2d53d5ce5d3207e3b43c9c6c59.png)
Create a new group and add members
Use the portal service to create a new group and add members in your portal.