Select to view content in your preferred language

Check for Existing Graph

330
1
Jump to solution
09-18-2024 09:13 AM
Labels (1)
DwightLanier
Occasional Contributor

I’m using the arcgis Python API to build, populate, and edit a knowledge graph. I want to be able to check for the existence of a graph prior to making one. My current approach involves a try/except where I build the graph create statement and try to make one. If there’s an exception raised then I just build the url and connect. 

while this works, I wonder if there’s a more elegant solution to check for the name of that graph? Would this involve searching for all Portal graph items and then looking in that list? I suppose that would get fairly lengthy and could be expensive in itself. 

thanks for any advice. 

0 Kudos
1 Solution

Accepted Solutions
MeganBanaski1
Esri Contributor

You can use gis.content.search which you can provide a query (the name of the graph you are looking for) as well as the item_type of 'Knowledge Graph'. This should return the single item if it exists. You can find more information on the parameters for search here: https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html

View solution in original post

1 Reply
MeganBanaski1
Esri Contributor

You can use gis.content.search which you can provide a query (the name of the graph you are looking for) as well as the item_type of 'Knowledge Graph'. This should return the single item if it exists. You can find more information on the parameters for search here: https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html