Use the ArcGIS for Python API
from arcgis.gis import GIS
## or use GIS("agol_url", "username", "password")
agol = GIS("home")
item = agol.content.get("FS_ITEM_ID")
## key: domain name, value: dictionary code:description
domains_dict = {}
## for each layer/table
## replace .layers with .tables to access tables instead
for lyr in item.layers:
## for each field in the layer/table
for fld in lyr.properties.fields:
## if there is a coded domain
if fld.domain and fld.domain.type == "codedValue":
## get the domain name
domain_name = fld.domain.name
## this dictionary will represent the key as the code
## and the value as the description
entry_dict = {}
## for each code value pair
for entry in fld.domain.codedValues:
for code, value in entry.items():
## add them to the entry_dict
entry_dict[entry.code] = entry.name
## add to the domain_dict
domains_dict[domain_name] = entry_dict
for name, codes in domains_dict.items():
print(name, codes)