Update IUCN API integration to use v4 and correct token authentication method.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: e931b5ab-041b-42e7-baf1-50017869cef6
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/e19c6a51-7e4c-4bb8-a6a6-46dc00f0ec99/9b4142b7-2774-47f3-b952-2a4615adb390.jpg
This commit is contained in:
Magnus-SmariSma
2025-03-20 23:36:10 +00:00
parent 953cc956ce
commit 119c3b2f7c

View File

@ -35,9 +35,9 @@ export async function registerRoutes(app: Express): Promise<Server> {
// If IUCN token is provided, try to validate it // If IUCN token is provided, try to validate it
if (tokenData.iucnToken) { if (tokenData.iucnToken) {
try { try {
await axios.get("https://apiv4.iucnredlist.org/api/v4/version", { await axios.get("https://api.iucnredlist.org/api/v4/information/api_version", {
headers: { params: {
"Authorization": `Bearer ${tokenData.iucnToken}` token: tokenData.iucnToken
} }
}); });
iucnValid = true; iucnValid = true;
@ -324,8 +324,8 @@ export async function registerRoutes(app: Express): Promise<Server> {
try { try {
// Check if the API is working by hitting the version endpoint // Check if the API is working by hitting the version endpoint
const response = await axios.get("https://api.iucnredlist.org/api/v4/information/api_version", { const response = await axios.get("https://api.iucnredlist.org/api/v4/information/api_version", {
headers: { params: {
"Authorization": `Bearer ${iucnToken}` token: iucnToken
} }
}); });
@ -401,10 +401,8 @@ export async function registerRoutes(app: Express): Promise<Server> {
try { try {
// Use the v4 API with scientific name endpoint // Use the v4 API with scientific name endpoint
const response = await axios.get("https://api.iucnredlist.org/api/v4/taxa/scientific_name", { const response = await axios.get("https://api.iucnredlist.org/api/v4/taxa/scientific_name", {
headers: {
"Authorization": `Bearer ${iucnToken}`
},
params: { params: {
token: iucnToken,
genus_name: genusName, genus_name: genusName,
species_name: speciesName || "" species_name: speciesName || ""
} }