How could we verify service urls from json file whether available or not in arcgis portal using python

1460
4
Jump to solution
06-14-2021 10:58 AM
by Anonymous User
Not applicable

Hi All,

My requirement is need to verify the urls given by some external users in json file. i need to load the json and read urls from it , need to verify whether service urls exists or not in portal using arcgis python api.

0 Kudos
1 Solution

Accepted Solutions
MehdiPira1
Esri Contributor

@Anonymous User ,

You can use the following script to get the existing portal services in a list. Then compare it with the url list from json.

from arcgis import GIS

gis = GIS("portal url", username, password, verify_cert=False)

# for feature layers 
fcs = gis.content.search("*", item_type="Feature Layer", max_items=100)
portal_service_urls = [fc.url for fc in fcs]
.....
json_urls = [...]

# Compare the 2 lists
set(portal_service_urls) & set(json_urls)

 

I hope that helps.

View solution in original post

4 Replies
DanPatterson
MVP Esteemed Contributor

moved to ArcGIS API for Python Questions - Esri Community to give you a better chance of getting an answer


... sort of retired...
0 Kudos
by Anonymous User
Not applicable
Thank you Dan 😊
0 Kudos
jas_eagle
Esri Contributor

If you only need to check the existence of the endpoint URLs in the json, you could do something like this with a simple GET request. A HEAD request is also an option, but results can be unreliable.

 

import requests

def url_exists(url):
    req = requests.get(url)
    if req.status_code == 200:
        print('Endpoint exists')
        return True

...
for url in your_json['endpoints']:
   url_exists(url)
...

 

 

MehdiPira1
Esri Contributor

@Anonymous User ,

You can use the following script to get the existing portal services in a list. Then compare it with the url list from json.

from arcgis import GIS

gis = GIS("portal url", username, password, verify_cert=False)

# for feature layers 
fcs = gis.content.search("*", item_type="Feature Layer", max_items=100)
portal_service_urls = [fc.url for fc in fcs]
.....
json_urls = [...]

# Compare the 2 lists
set(portal_service_urls) & set(json_urls)

 

I hope that helps.