Select to view content in your preferred language

Python - Get the services layers used in a Portal Dashboard

701
4
Jump to solution
06-29-2023 04:09 AM
Labels (2)
Alex2
by
New Contributor

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!

 

 

 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

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.

jcarlson_0-1688043979103.png

 

- Josh Carlson
Kendall County GIS

View solution in original post

4 Replies
jcarlson
MVP Esteemed Contributor

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.

jcarlson_0-1688043979103.png

 

- Josh Carlson
Kendall County GIS
maya_fromstein
New Contributor III

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))

 

0 Kudos
jcarlson
MVP Esteemed Contributor

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!

- Josh Carlson
Kendall County GIS
0 Kudos
Alex2
by
New Contributor

Thank you Josh!  This code helped me a lot.

 

0 Kudos