Learn how to use the portal service to set the sharing level for an item in your portal.
Prerequisites
You need an ArcGIS Location Platform, ArcGIS Online, or ArcGIS Enterprise account to use your portal.
Steps
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.
Create a new private item
You will create a new web map in your portal. The default sharing level will be private. In a later step, you will use the web map item ID to change the sharing level to public using the portal service.
- In a different tab, sign in to your portal.
- Click on Map to open up Map Viewer.
- Add a basemap, layer, and viewpoint for your map.
- Click Save > Save as.
- Provide a title and tags for your web map. Then, click Save.
- In the URL part of your browser, copy the web map item ID and store it in a safe location. You can find the item ID in
https
. You will use this item ID in a later step.://arcgis.com/apps/mapviewer/index.html?webmap= <ITEM _ID >
Perform a share
request
Now, you will be changing the sharing level of your item from private to public using the portal service.
- Set the request type to
POST
. - In the URL field, type in
https
. Replace://arcgis.com/sharing/rest/content/users/ <USER _NAME >/items/ <ITEM _ID >/share <USER
with your username and_NAME > <ITEM
with the item ID you copied in the previous step._ID > - Set the
f
parameter topjson
in the parameter list. - Set the
everyone
parameter totrue
to set the sharing level to public. To see other sharing levels, go to Sharing items. - Set the
token
parameter to your access token. - Set the
q
parameter totype
in the parameter list.: " Web Map" - Run the request.
POST https://arcgis.com/sharing/rest/content/users/<USER_NAME>/items/<ITEM_ID>/share
Content-Type: application/x-www-form-urlencoded
&f=json
&everyone=true
&token=<YOUR_ACCESS_TOKEN>
View the results
Go back to your portal and you should see that the sharing level of your item has changed to public. Your code may also print an output like this to verify that the operation was successful:
{
"notSharedWith": [],
"itemId": "<ITEM_ID>"
}
What's next
Copy a hosted layer item
Use the portal service to copy a hosted layer item in your portal.
Create a new group and add members
Use the portal service to create a new group and add members in your portal.