Select to view content in your preferred language

ArcGIS Api for Python - set content status on Item

2031
5
Jump to solution
12-17-2019 10:48 AM
DavidColey
MVP Regular Contributor

Hello - does anyone know how to set the content status on an item?  Currently, the api will allow you to read the content status property, but there seems to be no way to set the content status.  Something like:

portItem.update(item_properties={'content_status' : 'org_authoritative'})

would be ideal but 'content_status is not a property that can be set as part of item_properties, even as the json return does show content_status as contentStatus.  

0 Kudos
1 Solution

Accepted Solutions
LorneDmitruk2
Regular Contributor

Hi, 

All you have to do is the following:

portItem.content_status = 'authoritative'

View solution in original post

5 Replies
LorneDmitruk2
Regular Contributor

Hi, 

All you have to do is the following:

portItem.content_status = 'authoritative'
DavidColey
MVP Regular Contributor

Thanks Lorne, yes that did it.  'org_authoritative' for portal.  I thought I tried that first thing, but sadly the api documentation isn't as intuitive as maybe it should be.  If interested, you can follow the content_status property setting with an Item.protect(enable=False) to remove delete protection, as I've been tripped up many times by having a layer set with delete protection . . .

ToddW_stl
Esri Contributor

 found this super helpful article today by one of our Esri Community's newest MVPs, @Clubdebambos !

from the Esri docs:

 

DavidColey
MVP Regular Contributor

Yes, I've been doing this for about 5 years now:

gis = GIS("https://yourorg.maps.arcgis.com/", "username", "pw")
try:
    pubGroups = gis.groups.search(query='title:Some Group Title', max_groups=1000)
    for pubGroup in pubGroups:
        #print (pubGroup.title)
        if (pubGroup.title == 'Some Group Title Layers Group'): 
            print (pubGroup.title)
            items = pubGroup.content()
            #print (items)
            for item in items:
                #print(item.name)
                item.content_status = 'authoritative'
                item.protect(enable=False)
                #print(item.content_status)          
        
            message = message + "\n" + (pubGroup.title) + " Itens Sucessfully Reauthorized"

except Exception:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    e = sys.exc_info()[1]
    print(e.args[0])
    print ("Line %i" % tb.tb_lineno)
    message = message + "\n" + "Line %i" % tb.tb_lineno
    message = message + "\n" + str(e

 

In this way, you can just loop through your groups and the items in each group and set its content status and its protect status.  I do this because each week as my collaborated layers sync by reference from portal to arcgis online, I need to re-authorize the layers.

More importantly though, for the layers in the workspace collaborations to sync without fail I need to remove the delete protect status....

ToddW_stl
Esri Contributor

awesome, nice work.  thanks for marking a solution!

0 Kudos