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.
Solved! Go to Solution.
@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.
moved to ArcGIS API for Python Questions - Esri Community to give you a better chance of getting an answer
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)
...
@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.