Select to view content in your preferred language

The list of feature layers containing specific layers are not listed.

01-25-2022 08:10 AM
New Contributor III


I have many feature service in my portal which contains 4 to 6 layers in each of them, I wanted to list all the feature service which contain a specific layer called WETTBEWER which is layer (0) in all the feature services. I have the following code, but nothing is returned in the results, What Am I doing wrong ?? The specific process is done in the


"url": "https://url/portal/",
"username": "user",
"query": "title: WETTBEWER",
"item_type": "Feature Service",
"max_items": 400


import json

class JsonReader:

        def __init__(self, filename):
               self.filename = filename

       def read_json_file(self):
              with open(self.filename) as file:
                     data = json.load(file)
             return data

      def get_config(self, config):
             loaded_json = self.read_json_file()
             config = loaded_json[config]
             return config


from arcgis.gis import GIS

class PortalConnection:
        def __init__(self, url, username, password):
              self.url = url
              self.username = username
              self.password = password

def connect(self, query, layer, max_items):
# Connection to ArcGIS Enterprise using a built-in account
       print("Portal for ArcGIS as a built in user")
      gis_portal = GIS(self.url, self.username, self.password)
      print("Logged in as: " +
      return gis_portal, query, layer, max_items


class EsriApi:

         def __init__(self, portal, item_type, query, max_items):
                self.item_type = item_type
                self.query_ = query
                self.portal = portal
                self.max_items = max_items

       def query(self):
              api_query_result =,                    item_type=self.item_type, max_items=self.max_items)
              return api_query_result


class JsonWriter:

         def __init__(self,api_query_result):
               self.api_query_result = api_query_result

         def printResults(self):

               for item in self.api_query_result:
                      layers = item.layers
                      for lyr in layers:
                                 print(, item.url,["id"],             ["name"])
                            except Exception as e:


from json_reader import JsonReader
from portal_connection import PortalConnection
from esri_api import EsriApi
from json_writer import JsonWriter

jreader = JsonReader('config.json')
url = jreader.get_config("url")
username = jreader.get_config("username")
password = jreader.get_config("password")
query = jreader.get_config("query")
layer = jreader.get_config("item_type")
max_items = jreader.get_config("max_items")

con = PortalConnection(url, username, password)
portal, query, layer, max_items = con.connect(query, layer, max_items)

esri_api = EsriApi(portal, layer, query, max_items)
results = esri_api.query()

jsonWriter = JsonWriter(results)


Thank you for the insights...

0 Kudos
0 Replies