Python API query_related_records() how to?

11-01-2018 10:51 AM
Occasional Contributor


I have a feature layer containing points. I have a related table that has a multiple records for each point feature.

How can I query and use the data from the related records?

From the python API documentation I wrote the following in Jupyter Notebook:

# get the feature layer collection from AGOL
feature_layer_collection = gis.content.get('08d12e0*****4379bd5881f26539838e')

# get the feature layer of interest
feature_layer = feature_layer_collection.layers[0]

# get the related table of interest
feature_table = feature_layer_collection.tables[0]

# query the related records from feature_table
# I am using the "objectid" field and "globalid" field from feature_layer

related_query = feature_layer.query_related_records(object_ids='objectid', relationship_id='globalid')

I get the error:

RuntimeError:  Unable to perform query. Please check your parameters. (Error Code: 400)
  • Note:
    The feature layer and table are indeed related 1 to many globalid to parentglobalid

I haven't been able to find a good example to model from. Any help would be appreciated.

1 Reply
Occasional Contributor

So I figured it out by reading the REST API documentation Query Related Records (Feature Service)—ArcGIS REST API: Services Directory | ArcGIS for Developers 

Just in case anyone is as baffled as I was:

the object ID it is asking for is that actual object ID of the source feature

the relationship id is an identifier you can find by looking at the service page under "Relationships:"

good luck