Hi there!
I'm trying to get all the services, layers, webmapps...etc, that are dependent between each other in my organization via python.
I can get this information of diferent elements using the method "dependent_upon()" and "dependent_to()", but it does not retrieve this information for some elements, such as Dasboards or some aplications.
Is there a way to get which features services are consumed by a dashboard via python?
Thanks!
Solved! Go to Solution.
If you use the get_data method on the dashboard Item, you can search through the JSON and find all referenced layers.
from arcgis.gis import GIS
import re
gis = GIS('your portal url')
# get dashboard json
dash = gis.content.get('itemid of dashboard').get_data()
# pull out all itemids of maps / data layers w/ regex; push unique values into list
matches = []
[matches.append(m) for m in re.findall('[a-f0-9]{32}', str(dash)) if m not in matches]
Once you have your matches list, you can do other things with it, like pull the URLs or titles.
If you use the get_data method on the dashboard Item, you can search through the JSON and find all referenced layers.
from arcgis.gis import GIS
import re
gis = GIS('your portal url')
# get dashboard json
dash = gis.content.get('itemid of dashboard').get_data()
# pull out all itemids of maps / data layers w/ regex; push unique values into list
matches = []
[matches.append(m) for m in re.findall('[a-f0-9]{32}', str(dash)) if m not in matches]
Once you have your matches list, you can do other things with it, like pull the URLs or titles.
Hi! Sorry, joining the party very late.
Would you mind explaining how that regex expression (in line 11 of your code) accesses the itemIds? I am still a python newb and so still struggle with regex, sorry if this is obvious.
Very much appreciate your help, thanks!
re.findall('[a-f0-9]{32}', str(dash))
You should check out regex101.com, it has loads of resources for understanding regex. But here's the plain English version.
[a-f0-9] : Match a single character from a-f or from 0 to 9. ItemIDs are hexidecimal, so they can have digits and the first 6 letters of the alphabet.
{32} : Whatever precedes this, match it 32 times.
So, it should find any 32-character line of text consisting of digits, a, b, c, d, e, or f. Which is an ItemID!
Thank you Josh! This code helped me a lot.