<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Filter Services by those which contain .MapServer to get Service Manifest in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1231437#M7995</link>
    <description>&lt;P&gt;This script print out a few mapserver and then return this KeyError message...&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "Q:\Aqua_ArcGIS\WebServiceInfoExtract\test\test7.py", line 23, in &amp;lt;module&amp;gt;&lt;BR /&gt;fcnam = b['databases'][0]['datasets'] #scan the JSON and fine the list of feature classes&lt;BR /&gt;KeyError: 'databases'&lt;/P&gt;&lt;P&gt;Have any idea?&lt;/P&gt;</description>
    <pubDate>Mon, 14 Nov 2022 20:49:18 GMT</pubDate>
    <dc:creator>HaThach1</dc:creator>
    <dc:date>2022-11-14T20:49:18Z</dc:date>
    <item>
      <title>Filter Services by those which contain .MapServer to get Service Manifest</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1217313#M7828</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;Our team are trying to create a single table which creates a link between a portal item its service URL and the feature class(s) and database it sits in. Trawling the forum has led me to look at using the service manifest as a source for this for which I've had some success however I've now encountered an issue where as I loop through each Service within a folder I hit an error if the service holds no manifest. This is because geoprocessing services (e.g. A custom data export / print service) holds no manifest and so the script fails.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried a TRY function and also various way of trying to create a test case to filter our non MapServer services but with little success. This is mainly as each service in the returned list isn't string but a custom ArcGIS Server data type which is limited.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have any ideas on how to filter services?&amp;nbsp;&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;from arcgis.gis import *&lt;BR /&gt;import json&lt;/P&gt;&lt;P&gt;gis = GIS("portal", "username", "password",verify_cert=False,)&lt;/P&gt;&lt;P&gt;print("Successfully logged in as: " + gis.properties.user.username)&lt;/P&gt;&lt;P&gt;servers = gis.admin.serverss = servers.list() #list federated servers&lt;BR /&gt;server1 = s[1] #isolate portal server in list&lt;BR /&gt;services = server1.services.list(folder="Shared") #list the services within the folder "Shared"&lt;/P&gt;&lt;P&gt;for service in services: #list the manifest for each service URL&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;ii = service.iteminformation&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;manifest = ii.manifest&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;a = json.dumps(manifest)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;b = json.loads(a)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;fcnam = b['databases'][0]['datasets'] #scan the JSON and fine the list of feature classes&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;dbnam = b['databases'][0]['onServerName'] # scan the JSON and find the DB name&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;for x in fcnam:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print(service,dbnam,x['onServerName']) #print service with list of db fc names&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Sep 2022 11:04:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1217313#M7828</guid>
      <dc:creator>JaymieCroucher</dc:creator>
      <dc:date>2022-09-29T11:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: Filter Services by those which contain .MapServer to get Service Manifest</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1219430#M7866</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/71517"&gt;@JaymieCroucher&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think all you need to do what you are asking above to filter on MapServer services is to add the following inside your "for service in services", e.g.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;for service in services: #list the manifest for each service URL&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if service.type == "MapServer":&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ii = service.iteminformation&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; # the rest of your code&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 16:16:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1219430#M7866</guid>
      <dc:creator>RobertAkroyd1</dc:creator>
      <dc:date>2022-10-06T16:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: Filter Services by those which contain .MapServer to get Service Manifest</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1219534#M7867</link>
      <description>&lt;P&gt;Very grateful Rob, worked a dream&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 18:53:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1219534#M7867</guid>
      <dc:creator>JaymieCroucher</dc:creator>
      <dc:date>2022-10-06T18:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: Filter Services by those which contain .MapServer to get Service Manifest</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1231437#M7995</link>
      <description>&lt;P&gt;This script print out a few mapserver and then return this KeyError message...&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;BR /&gt;File "Q:\Aqua_ArcGIS\WebServiceInfoExtract\test\test7.py", line 23, in &amp;lt;module&amp;gt;&lt;BR /&gt;fcnam = b['databases'][0]['datasets'] #scan the JSON and fine the list of feature classes&lt;BR /&gt;KeyError: 'databases'&lt;/P&gt;&lt;P&gt;Have any idea?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 20:49:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1231437#M7995</guid>
      <dc:creator>HaThach1</dc:creator>
      <dc:date>2022-11-14T20:49:18Z</dc:date>
    </item>
    <item>
      <title>Re: Filter Services by those which contain .MapServer to get Service Manifest</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1231594#M7997</link>
      <description>&lt;P&gt;Looks like the JSON for that service did not include a "databases" element, so you should check for that in the code first, e.g.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;b = json.loads(a)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if&amp;nbsp;&lt;SPAN&gt;b['databases']:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fcnam = b['databases'][0]['datasets'] #scan the JSON and fine the list of feature classes&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 08:29:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1231594#M7997</guid>
      <dc:creator>RobertAkroyd1</dc:creator>
      <dc:date>2022-11-15T08:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: Filter Services by those which contain .MapServer to get Service Manifest</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1231622#M7999</link>
      <description>&lt;P&gt;Sorry I only recently managed to get this working in anger. The below provides a CSV output of the following:&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Each Feature Class and sourced database provided within a service&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;The Service URL and Name&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;The Portal URL and ID&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import json&lt;BR /&gt;import csv&lt;BR /&gt;import os&lt;BR /&gt;from arcgis.gis import *&lt;/P&gt;&lt;P&gt;#Step 1 - Import all libraries and setup connection to portal and location of csv&lt;/P&gt;&lt;P&gt;gis = GIS("Portal URL", username, password,verify_cert=False,)&lt;BR /&gt;outputFile=r"\\Output CSV Location"&lt;BR /&gt;print("Successfully logged in as: " + gis.properties.user.username)&lt;/P&gt;&lt;P&gt;#Step 2 - wipe the CSV and set header values&lt;/P&gt;&lt;P&gt;with open(outputFile, 'w', newline='') as ResultFile:&lt;BR /&gt;wr = csv.writer(ResultFile)&lt;BR /&gt;header = 'Portal Item', 'Portal Item ID','Service URL','Portal URL','DB Name', 'Feature Class Name'&lt;BR /&gt;wr.writerow(header)&lt;/P&gt;&lt;P&gt;#Step 3 - Find hosting server and list and join all services across folders&lt;/P&gt;&lt;P&gt;servers = gis.admin.servers&lt;BR /&gt;s = servers.list()&lt;BR /&gt;server1 = s[0] #isolate portal server in list&lt;BR /&gt;services_1 = server1.services.list(folder="Server Folder Name 1") #list the services within the folder "root"&lt;BR /&gt;services_2 = server1.services.list(folder="Server Folder Name 2")&lt;BR /&gt;services_3 = server1.services.list(folder="Server Folder Name 3")&lt;BR /&gt;services_4 = server1.services.list(folder="Server Folder Name 4")&lt;BR /&gt;services = services_1 + services_2 + services_3 +services_4&lt;/P&gt;&lt;P&gt;#Step 4a - Isolate only MapServer services and print the manifest for each service&lt;BR /&gt;#Step 4b - Extract service properties from the Portal&lt;BR /&gt;#Step 4c - Sift through JSON from manifest and extract feature class and database&lt;BR /&gt;#Step 5 - Write out many to one relationship of feature class to service to portal item&lt;/P&gt;&lt;P&gt;for service in services:&lt;BR /&gt;if service.type == "MapServer":&lt;BR /&gt;ii = service.iteminformation&lt;BR /&gt;manifest = ii.manifest&lt;BR /&gt;a = json.dumps(manifest)&lt;BR /&gt;b = json.loads(a)&lt;BR /&gt;piid = service.properties.portalProperties.portalItems&lt;BR /&gt;pin = service.properties.serviceName&lt;BR /&gt;piidi = piid[0]['itemID']&lt;BR /&gt;piidiurl = "Portal Map Viewer URL" + piidi&lt;BR /&gt;fcnam = b['databases'][0]['datasets'] #scan the JSON and fine the list of feature classes:&lt;BR /&gt;dbnam = b['databases'][0]['onServerName'] # scan the JSON and find the DB name&lt;BR /&gt;for x in fcnam:&lt;BR /&gt;with open(outputFile, 'a',newline='') as ResultFile:&lt;BR /&gt;wr = csv.writer(ResultFile)&lt;BR /&gt;ContentRow = pin,piidi,service,piidiurl,dbnam,x['onServerName']&lt;BR /&gt;wr.writerow(ContentRow)&lt;BR /&gt;loops = loops+1&lt;BR /&gt;&lt;BR /&gt;print("Successfully wrote " +str(loops) + " records to the manifest CSV")&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 09:51:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1231622#M7999</guid>
      <dc:creator>JaymieCroucher</dc:creator>
      <dc:date>2022-11-15T09:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Filter Services by those which contain .MapServer to get Service Manifest</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1231752#M8001</link>
      <description>&lt;P&gt;I got the same error after updating the script.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HaThach1_0-1668525123886.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/55993i827155551AC4AABB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HaThach1_0-1668525123886.png" alt="HaThach1_0-1668525123886.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 15:13:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1231752#M8001</guid>
      <dc:creator>HaThach1</dc:creator>
      <dc:date>2022-11-15T15:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: Filter Services by those which contain .MapServer to get Service Manifest</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1231761#M8002</link>
      <description>&lt;P&gt;Hi Jamie,&lt;/P&gt;&lt;P&gt;I tried your script as well and got&amp;nbsp;&lt;/P&gt;&lt;P&gt;AttributeError: 'PropertyMap' instance has no attribute 'portalProperties'&lt;/P&gt;&lt;P&gt;even if I comment out variable piid, now I'm getting the same error as before relate to&lt;/P&gt;&lt;P&gt;KeyError: 'databases'&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HaThach1_0-1668526200868.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/55995iB97FF7D6325ED262/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HaThach1_0-1668526200868.png" alt="HaThach1_0-1668526200868.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 15:30:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1231761#M8002</guid>
      <dc:creator>HaThach1</dc:creator>
      <dc:date>2022-11-15T15:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: Filter Services by those which contain .MapServer to get Service Manifest</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1231773#M8003</link>
      <description>&lt;P&gt;Do you get a list of services from the hosting server?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have you manually checked the JSON manifest through Server Manager for a specific service?&lt;/P&gt;&lt;P&gt;(Should look like:&amp;nbsp;&lt;A href="https://resources.arcgis.com/en/help/server-admin-api/serviceManifest.html" target="_blank"&gt;https://resources.arcgis.com/en/help/server-admin-api/serviceManifest.html&lt;/A&gt;. Gained through Server Manager) Example URL here:&amp;nbsp;&lt;A href="https://portal.domain/server/admin/services/ServerFolder/ServiceName.MapServer/iteminfo/manifest/manifest.json" target="_blank"&gt;https://portal.domain/server/admin/services/ServerFolder/ServiceName.MapServer/iteminfo/manifest/manifest.json&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 15:59:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1231773#M8003</guid>
      <dc:creator>JaymieCroucher</dc:creator>
      <dc:date>2022-11-15T15:59:02Z</dc:date>
    </item>
    <item>
      <title>Re: Filter Services by those which contain .MapServer to get Service Manifest</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1231880#M8006</link>
      <description>&lt;P&gt;I didn't get pass this error&lt;/P&gt;&lt;P&gt;AttributeError: 'PropertyMap' instance has no attribute 'portalProperties'&lt;/P&gt;&lt;P&gt;As for the JSON manifest check, I was able to constructed the URL from your example and see the JSON manifest of a specific service.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HaThach1_0-1668535538695.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/56027i408B1F56E5FAA7D4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HaThach1_0-1668535538695.png" alt="HaThach1_0-1668535538695.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 18:06:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/filter-services-by-those-which-contain-mapserver/m-p/1231880#M8006</guid>
      <dc:creator>HaThach1</dc:creator>
      <dc:date>2022-11-15T18:06:22Z</dc:date>
    </item>
  </channel>
</rss>

