API - would like to get Observations of Lepidoptera

I want to use the API to get a list of Butterflies observed within say 50km of my current location.

https://api.inaturalist.org/v1/observations/species_counts?rank=species&lat=xxxx.xx&lng=xxx.xx&radius=50

This works for all observations. How do I specify ONLY the Order Lepidoptera?

I think that taxon_id might be the key, but unsure how I would get the taxon_id of Lepidoptera.

And to be more accurate, I want to exclude Moths from the list of observations, so I really want the subOrder of Rhopalocera.

From the Explore page, search for a taxon and the id will show up in the URL.

iNat doesn’t use Rhopalocera, but it does have Papilionoidea, taxon_id=47224, so you can add &taxon_id=47224 to your query.

1 Like

Thanks much; I did find that just now. So, what is the best method for getting the taxon_id for this superfamily? Can I assume that it is via the /taxa endpoint? Since I am new to this API, just want to try to use it correctly and as intended. Is there a link to a page that describes the links between the various APIs, etc. and I will be happy to go there? I haven’t found such a thing yet that explains taxon_id, place_id, and so on and how to cross reference.

For example, I could use /taxa or /taxa/autocomplete I guess. Which is preferred?

https://api.inaturalist.org/v1/taxa?q=papilionoidea returns 2 results.

If you are looking for a general way to find a taxon_id from a scientific name, I think /taxa or /search?sources=taxa are probably your best bets.
All the general API info is found on these pages: https://api.inaturalist.org/v1/docs/ and https://www.inaturalist.org/pages/api+reference
I’m not totally sure what you mean by links between the various APIs or what sort of further explanation you’re looking for. Many of the terms used in the API are described in relation to the Explore/Identify interface here, and they apply the same way to the API, so that might be helpful.

1 Like

Perfect. That is what I was looking for. Just trying to learn what-means-what here. And how to properly use the API. A couple hours of playing and I think I have the basics down now.

1 Like

One more question if I may. It seems that /observations/species_counts returns the observations sorted by most to least number of observations.
How might I get a list in taxonomic order if desired?

I don’t think that endpoint will do a taxonomic sort, only ascending or descending by number of observations. If you want to sort them yourself, I believe iNat uses ancestry + taxon_id as the field to approximate taxonomic sort (which isn’t a “true” taxonomic sort anyway).

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