From ecf40d52945ec82761db5e4b31852b52743f0087 Mon Sep 17 00:00:00 2001 From: Magnus-SmariSma <20734986-Magnus-SmariSma@users.noreply.replit.com> Date: Thu, 20 Mar 2025 23:23:34 +0000 Subject: [PATCH] Add debug logging to IUCN API calls to inspect response structures. 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/1cb15499-88b2-4bbc-afd6-845ffc4e44b5.jpg --- server/routes.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/server/routes.ts b/server/routes.ts index 7cdaac5..1f18f4f 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -394,6 +394,11 @@ export async function registerRoutes(app: Express): Promise { } }); + // Debug the response structure + console.log("IUCN API response structure:", + Object.keys(response.data), + response.data.result ? `Result has ${response.data.result.length} items` : "No result property"); + return res.json({ success: true, data: response.data, @@ -471,12 +476,20 @@ export async function registerRoutes(app: Express): Promise { const taxonId = taxaResponse.data.result[0].taxonid; // Now retrieve the threats using the taxon ID - const threatsResponse = await axios.get(`https://apiv4.iucnredlist.org/api/v4/threats/species/id/${taxonId}`, { + const threatsResponse = await axios.get(`https://apiv4.iucnredlist.org/api/v4/threats`, { headers: { "Authorization": `Bearer ${activeToken.iucnToken}` + }, + params: { + taxonid: taxonId } }); + // Debug the response structure + console.log("IUCN Threats API response structure:", + Object.keys(threatsResponse.data), + threatsResponse.data.result ? `Result has ${threatsResponse.data.result.length} items` : "No result property"); + return res.json({ success: true, data: threatsResponse.data, @@ -554,12 +567,20 @@ export async function registerRoutes(app: Express): Promise { const taxonId = taxaResponse.data.result[0].taxonid; // Now retrieve the habitats using the taxon ID - const habitatsResponse = await axios.get(`https://apiv4.iucnredlist.org/api/v4/habitats/species/id/${taxonId}`, { + const habitatsResponse = await axios.get(`https://apiv4.iucnredlist.org/api/v4/habitats`, { headers: { "Authorization": `Bearer ${activeToken.iucnToken}` + }, + params: { + taxonid: taxonId } }); + // Debug the response structure + console.log("IUCN Habitats API response structure:", + Object.keys(habitatsResponse.data), + habitatsResponse.data.result ? `Result has ${habitatsResponse.data.result.length} items` : "No result property"); + return res.json({ success: true, data: habitatsResponse.data,