AGOL Arcpy count features in a hosted services from REST

12-09-2019 10:38 AM
Occasional Contributor III

Is there a way to get the total count of features in a single service with python?

0 Kudos
2 Replies
MVP Regular Contributor

See: Query (Feature Service)

The Query operation is performed on a feature service resource. The result of this operation is either a feature set for each layer in the query or a count of features for each layer (if returnCountOnly is set to true) or an array of feature IDs for each layer in the query (if returnIdsOnly is set to true).

I did a quick test, with returnCountOnly set to true and using a where "1=1". It returned a count.

URL = ""

query_dict = {
    "where" : "1=1",
    "returnCountOnly" : "true",
    "returnGeometry" : "false",
    "f": "json", "token": token['token'] }

jsonResponse = urllib.urlopen(URL, urllib.urlencode(query_dict))

response = json.loads(

print response

# prints: {u'count': 486, u'serverGens': {u'serverGen': 461482, u'minServerGen': 65364}}
0 Kudos
MVP Regular Contributor

If you are using the Python API, see: arcgis.features.FeatureLayer.query

and use  return_count_only=True