Learn how to use the portal service to create a new group in your portal, and add members to the group.
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:
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, .
Copy a hosted layer item
- Add the following import statement to your code.
main.py
Use dark colors for code blocks from arcgis.gis import GIS from arcgis.features import FeatureLayerCollection
- Establish a connection to the portal using the
GIS()
module.main.pyUse dark colors for code blocks from arcgis.gis import GIS from arcgis.features import FeatureLayerCollection # Replace with your actual username, password, and item ID username = 'your_username' password = 'your_password' feature_layer_item_id = 'your_feature_layer_item_id' # The item ID of the item you want to copy portal_url = 'https://www.arcgis.com' # Authenticate with ArcGIS Online gis = GIS(portal_url, username, password)
- Get the item using the
item
.I D main.pyUse dark colors for code blocks from arcgis.gis import GIS from arcgis.features import FeatureLayerCollection # Replace with your actual username, password, and item ID username = 'your_username' password = 'your_password' feature_layer_item_id = 'your_feature_layer_item_id' # The item ID of the item you want to copy portal_url = 'https://www.arcgis.com' # Authenticate with ArcGIS Online gis = GIS(portal_url, username, password) # Access the hosted feature layer item feature_layer_item = gis.content.get(feature_layer_item_id)
- Use the
clone_
method to create a deep copy of the feature layer item.items main.pyUse dark colors for code blocks from arcgis.gis import GIS from arcgis.features import FeatureLayerCollection # Replace with your actual username, password, and item ID username = 'your_username' password = 'your_password' feature_layer_item_id = 'your_feature_layer_item_id' # The item ID of the item you want to copy portal_url = 'https://www.arcgis.com' # Authenticate with ArcGIS Online gis = GIS(portal_url, username, password) # Access the hosted feature layer item feature_layer_item = gis.content.get(feature_layer_item_id) # Use the `clone_items` method to create an entirely new copy of the feature layer item cloned_items = gis.content.clone_items([feature_layer_item]) # Check the result of the clone operation if cloned_items: print(f"Successfully cloned the item. New item ID: {cloned_items[0].id}") else: print("Failed to clone the item.")
- Add the following import statement to your code.
rest-js.js
Use dark colors for code blocks import { ApiKeyManager } from '@esri/arcgis-rest-request'; import { getItem, addItem, getItemData, setItemData } from '@esri/arcgis-rest-portal';
- Establish a connection to the portal.
rest-js.js
Use dark colors for code blocks import { ApiKeyManager } from '@esri/arcgis-rest-request'; import { getItem, addItem, getItemData, setItemData } from '@esri/arcgis-rest-portal'; const apiKey = "YOUR_ACCESS_TOKEN"; const authentication = ApiKeyManager.fromKey(apiKey);
- Get the item and associated data.
rest-js.js
Use dark colors for code blocks import { ApiKeyManager } from '@esri/arcgis-rest-request'; import { getItem, addItem, getItemData, setItemData } from '@esri/arcgis-rest-portal'; const apiKey = "YOUR_ACCESS_TOKEN"; const authentication = ApiKeyManager.fromKey(apiKey); // Get the feature layer item details const itemDetails = await getItem(featureLayerItemId, { authentication }); const itemData = await getItemData(featureLayerItemId, { authentication });
- Define properties of a new item and add the new item using the
add
method.Item rest-js.jsUse dark colors for code blocks import { ApiKeyManager } from '@esri/arcgis-rest-request'; import { getItem, addItem, getItemData, setItemData } from '@esri/arcgis-rest-portal'; const apiKey = "YOUR_ACCESS_TOKEN"; const authentication = ApiKeyManager.fromKey(apiKey); // Get the feature layer item details const itemDetails = await getItem(featureLayerItemId, { authentication }); const itemData = await getItemData(featureLayerItemId, { authentication }); // Create a new item by copying details from the existing item const newItem = await addItem({ item: { title: `Copy of ${itemDetails.title}`, type: itemDetails.type, description: itemDetails.description, tags: itemDetails.tags, snippet: itemDetails.snippet, extent: itemDetails.extent, spatialReference: itemDetails.spatialReference, typeKeywords: itemDetails.typeKeywords, url: itemDetails.url, // Include the URL to retain the feature service URL }, authentication, });
- Set the underlying data for the newly added item.
rest-js.js
Use dark colors for code blocks import { ApiKeyManager } from '@esri/arcgis-rest-request'; import { getItem, addItem, getItemData, setItemData } from '@esri/arcgis-rest-portal'; const apiKey = "YOUR_ACCESS_TOKEN"; const authentication = ApiKeyManager.fromKey(apiKey); // Get the feature layer item details const itemDetails = await getItem(featureLayerItemId, { authentication }); const itemData = await getItemData(featureLayerItemId, { authentication }); // Create a new item by copying details from the existing item const newItem = await addItem({ item: { title: `Copy of ${itemDetails.title}`, type: itemDetails.type, description: itemDetails.description, tags: itemDetails.tags, snippet: itemDetails.snippet, extent: itemDetails.extent, spatialReference: itemDetails.spatialReference, typeKeywords: itemDetails.typeKeywords, url: itemDetails.url, // Include the URL to retain the feature service URL }, authentication, }); // Set the data for the new item await setItemData({ id: newItem.id, authentication, data: itemData, }); console.log(`Successfully cloned the feature layer. New item ID: ${newItem.id}`);
View the results
If successful, your code will print an output like this to verify that the operation was successful:
Successfully cloned the item. New item ID: <new_item_id>
Successfully cloned the feature layer. New item ID: <new_item_id>
What's next
![](/documentation/static/access-feature-layer-data-fe6f3f2d53d5ce5d3207e3b43c9c6c59.png)
Sign in and access your portal
Use the portal service to sign in and access your portal.
![](/documentation/static/access-feature-layer-data-fe6f3f2d53d5ce5d3207e3b43c9c6c59.png)
List items in your portal
Use the portal service to list items 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.