Select to view content in your preferred language

How to bulk delete protect and mark as authoritative?

1989
6
06-27-2019 11:42 AM
ThomasColson
MVP Alum

I have a bunch of (my) content that I want to mark as authoritative and delete protect in Portal 10.6.1. I see that there is an API for delete protect https://developers.arcgis.com/rest/users-groups-and-items/protect.htm is there something similar for mark as authoritative? And can this be done with Python?

6 Replies
RobertBorchert
Honored Contributor

0 Kudos
ThomasColson
MVP Alum

Looking for a python way to do this on thousands of items at once. ...

ThomasColson
MVP Alum

I see with https://community.esri.com/thread/220209-set-data-item-as-authoritative-with-api-for-python I can do it one item at a time....how to do on all items say, owned by Sasquatch? While I'm on this thread, how to assign the same number of items to a single Category, at once?

0 Kudos
RobertBorchert
Honored Contributor

Thousands???

Get a list of all your item id's  Put them in an Access table

Copy the python script to a new Access Table.  Two tables one that is thousands and one that is just the script.

Change the script so that the variables match your environment. other than <item id>

Add to the bottom of the script

del gis

del item1

this does not delete the gis or the item it just deletes them from the running python script so they can be used 1000's of times. 

add both tables to a create query session.  add the long one as the first field ad the script as the second field.  Then do a make table.   This will create a new table that has your id's on the left and the script on the right. 

Then make another query to replace the 

<item ID>

with the value from the left column.  

0 Kudos
RyanDickinson1
Regular Contributor

Thomas, we have been having some issues with 10.9.1 and overwriting services. I believe you are looking for something like this:

 

import arcpy
from arcgis.gis import GIS
objGIS = None
def msg(message):
arcpy.AddMessage(message)
return
def updateProtection(condition, item_id):
msg(f'Updating settings for {item_id}')
try:
objGIS = GIS(gis_url, username, password)
except Exception as e:
msg(e)
try:
for i in item_id.split(";"):
item = objGIS.content.get(f"{i}")
if condition == "enable":
item.protect(enable = True)
item.content_status = 'org_authoritative'
else:
item.protect(enable = False)
except Exception as e:
msg(e)
return
if __name__ == '__main__':
gis_url = arcpy.GetParameterAsText(0)
username = arcpy.GetParameterAsText(1)
password = arcpy.GetParameterAsText(2)
item_id = arcpy.GetParameterAsText(3)
condition = arcpy.GetParameterAsText(4)
updateProtection(condition, item_id)
msg("complete")

ToddW_stl
Esri Contributor

this article was super helpful to me figuring out how to mark a single item authoritative and enable delete protection via the API from one of Esri Community's newest MVPs, @Clubdebambos !

I'd recommend using search to narrow down your thousands of items by item type, then the for/in loop below to enable delete protection and mark as authoritative on each item in your list.

in the Python Window of ArcGIS Pro 3.4 / ArcGIS Enterprise 11.3:

items = gis.content.search(query='',item_type="xxx",)
len(items) # to get count of items in list
for item in items:
item.protect()
item.content_status = "authoritative"

additional search references:

How To: Find specific items using queries in the arcgis.gis module with ArcGIS API for Python

Accessing and creating content via the API (be sure to read the "About search" section)