Is there a better way to make API requests for observations ancestor taxa

Hello, I don’t know if this is just a question or a feature request.

I would be happy if someone can point my in the right direction. What I want to do is: Get the id of a certain taxa rank from an observation. In other words, starting from an observation id, I am querying the API for this observation. Then from the result I would like to know in which family is this observation.
From the object given back from the API, I can only see a .taxon.ancestor_ids or .taxon.ancestry but that means that I have to go through the entire array and query each taxon by id, and then filter wether the rank of this result is family. I would like there to be a way to query the observation and get information about the ancestors rank in addition to the id.

Then I would need to make much less requests to the API to get the one correct taxon.

(In the export page on the web, I can only export family name, and not the id of the taxon. So, I dont think that helps me.

not sure what the issue is. if you’re starting with an observation id, both GET /observations and GET /observations/{id} give you a taxon.ancestors array from which you can get the rank or rank level of any of the ancestor taxa.

are you fetching directly from the API, or are you going through some package?

I am using the inaturalistjs package for querying the API, but I checked with the API explanation website and it gives me the same. I am checking under Observation.taxon, but also Observation.communityTaxon only has a ancestor_ids property with an array of all the ancestor ids only, not the entire taxon object. That means I have to loop through those ids and query the API to see which one is the rank I want.

Edit: This means I have to query the API for several IDs that I do not need the info of really just to see which rank it is. It would be better if I know which single id to query from the results of the observation query.

Okay, so I have found now that in the Observation.identifications property each object of class Identification also has a taxon property and there is an ancestors array like you said with all the ancestor taxa as objects.

Then I would think that this is a bug in the API that the ancestorTaxa/ancestors property is not given for Observation.taxon and Observation.communityTaxon.

(Then I can loop through the identifications and check which one matches the community taxon and take the ancestors from there. Still I think it would be neater if the ancestors where also in Observation.taxon)

There’s a tradeoff between sending all data the end user may want and fast/small/efficient API responses. Ideally the API user could specify all and only the fields they want for all possible nested properties, and this is something we’re working on in a V2 of the API.

As it stands, it is intentional we don’t list all ancestors in all cases. The IDs should cover all taxa in the observation.taxon or observation.community_taxon properties, so there’s no real need to duplicate the ancestors in multiple places. But I understand how this is confusing as the user, not knowing what properties you’ll have to work with in all cases (again we’re addressing this in a new version of the API)

Also, FYI, you can fetch data for multiple taxa in a single API call, and we recommend you do this so save on total number of API calls. For example you could send all ancestor IDs, e.g.,2,3


I understand the tradeoffs, and am looking forward to v2 then.

I am aware of querying by multiple IDs for taxa, but this errors out for me when asking for somewhere over 100 ids. So cutting down the number of ids would also reduce the number of requests. But as I said I can use it from Identifications for now. Thank you.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.