I have a feature service with several coded value domains that I'm accessing as a spatially enabled dataframe using the python API.

As far as I can tell, the dataframe only holds the code for each field. I'd like to update those to the description from the domain. Is there a way to access the domain of the feature service through the API?

2 Answers 2


I am not aware of a functionality in the ArcGIS API for Python to accomplish this. However, you can do a workaround and get the values by querying the domains of the feature service using the ArcGIS REST API.

Using Python you would simply make the following request:

import requests

url = 'https:// <featureservice-url>/queryDomains'
params = {'f': 'json', 'layers': [1]}

r = requests.get(url, params)
data = r.json()

If the request was made correctly, data should be a dictionary similar to this one (adapted from the documentation linked above):

 "domains": [
   "type": "codedValue",
   "name": "CDOM_3",
   "fieldType": "esriFieldTypeInteger",
   "codedValues": [
     "name": "code 100 description",
     "code": "code 100"
     "name": "code 200 description",
     "code": "code 200"
     "name": "code 300 description",
     "code": "code 300"
   "mergePolicy": "esriMPTDefaultValue",
   "splitPolicy": "esriSPTDefaultValue"

It should then be rather straight forward to replace the coded values with their respective descriptions in the DataFrame. However, if it is not the case and you have trouble, leave a comment and I'll gladly update my answer.

  • 1
    For whatever reason the /queryDomains request returns a 400 error. Is it possible for a feature service to not have it enabled? However, your answer led me to just grabbing the JSON for the layer, which also has the domains listed for each field. Thanks! Jun 25, 2019 at 17:14

The Python API has a query_domains method for Feature Layer Collection objects. In order to use this the Feature Service requires a supportsQueryDomains property set to true. I have been unable to add/set this property for a Hosted Feature Service in AGOL. It does exist, however, in a referenced Feature Service in Portal i.e. data stored in SDE. The below code uses the the query_domains method on a Portal item

from arcgis import GIS
from arcgis.features import FeatureLayerCollection

agol = GIS("home")

item = agol.content.get("**fs_id**")
flc = FeatureLayerCollection(item.url, agol)
domains = flc.query_domains(layers=[2])


The output is a list of dictionaries containing properties for each domain. Here is an example of a dictionary in the list.

    'type': 'codedValue',
    'name': 'Domain_Name',
    'description': '',
    'codedValues': [
        {   'name': 'Description1',
            'code': 1
        {   'name': 'Description2',
            'code': 2
        {   'name': 'Description3',
            'code': 3
    'fieldType': 'esriFieldTypeSmallInteger',
    'mergePolicy': 'esriMPTDefaultValue',
    'splitPolicy': 'esriSPTDefaultValue'

Attempting to run this code on a Hosted Feature Service on AGOL results in an error.

The requested layer (layerId: queryDomains) was not found.
(Error Code: 400)

We can access the layer properties and extract the domain information for a Hosted Feature Service. The code below will print out a list of dictionaries similar to the query_domains method used in Portal.

from arcgis import GIS
from arcgis.features import FeatureLayerCollection

agol = GIS("home")

item = agol.content.get("**fs_id**")

## list to hold the domain information
domains_list = []

## get domains for specific layer
for fld in item.layers[0].properties.fields:
    if fld.domain:
        ## append each domain into the list
        if fld.domain not in domains_list:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.