Learn how to use the portal service to set the sharing level for an item in your portal.
Prerequisites
You need the following for this tutorial:
- Account: An ArcGIS Location Platform, ArcGIS Online, or ArcGIS Enterprise account.
- Authentication: A basic understanding of API key authentication or User authentication.
Steps
Implement authentication
You need an access token with the correct privileges for in this tutorial.
-
Go to the Create an API key tutorial and create an API key with the following privilege(s):
-
Privileges
- Admin privileges > Content > View all
- General privileges > Sharing
-
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.