How to download all mammals (taxa only, not observations)?

Hi everyone. I am one step further in creating a json or csv of all mammals with geo bounding boxes.

THE GOAL

interface GeoHook = {
// Reference
“id”: 42223,
“common_name”: “White-tailed Deer”,
“wikipedia_url”: “http://en.wikipedia.org/wiki/White-tailed_deer”

// Geography
p9714: “min_lat: …, max_lat: …, min_lon: …, max_lon: …“, // Geographic extent (geo range, boundary box(s) or location(s))
p2974: “urban, ocean, forest, desert, mangroove, arctic, tundra etc.“, // Environment type
};

THE FIRST THREE (id, common_name, wikipedia_url) YOU’LL FETCH EASILY WITH THIS PYTHON SCRIPT

import requests
import json

url = “https://api.inaturalist.org/v1/taxa”
all_mammals =
page = 1

while True:
params = {
“taxon_id”: 40151, # Mammalia
“rank”: “species”,
“per_page”: 200,
“page”: page
}

response = requests.get(url, params=params)
data = response.json()
results = data['results']

# Extract only the desired fields
for species in results:
    mammal = {
        "id": species['id'],
        "common_name": species.get('preferred_common_name', None),
        "wikipedia_url": species.get('wikipedia_url', None)
    }
    all_mammals.append(mammal)

print(f"Page {page}: {len(results)} species loaded")

if len(results) < 200:
    break

page += 1

print(f"\nTotal of {len(all_mammals)} mammal species found")

# Save as JSON file

with open(‘mammals.json’, ‘w’, encoding=‘utf-8’) as f:
json.dump(all_mammals, f, indent=2, ensure_ascii=False)

# Show first 5 entries

print(“\nExample entries:”)
for mammal in all_mammals[:5]:
print(mammal)

BUT HOW DO I GET THE GEOGRAPHY PART???

I could run all fetched ID’s like this with a script https://api.inaturalist.org/v1/observations?taxon_id=42069&geo=true and fetch only all geojson points and connect them to bounding boxes, but that feels like unnecessary effort, and by logic that will not work out either (how do i know which observation points belong in which square like on the INaturalist map for a species)

"geojson": {
        "type": "Point",
        "coordinates": [8.3248510361, 46.5978927612]
      },

I BASICALLY WANT THE DATA TO RENDER THESE OBSERVATIONS SQUARES ON MY MAP (i am aware not to render the exact points to avoid becoming the number 1 map for hunters :sweat_smile:)