I’m trying to fetch board game information from the BoardGameGeek XML API using Node.js. I have a valid API token, but every request returns a 403 Forbidden response.
Here’s my current setup:
async function getInfoFromBGG(gameId) {
const url = `https://rpggeek.com/xmlapi2/thing?id=${gameId}`
let result
const controller = new AbortController()
const timeoutId = setTimeout(() => controller.abort(), 5000)
try {
const response = await fetch(url, {
headers: {
"Authorization": "Bearer i put my token here",
"User-Agent": "BoardgameAlbum/1.0 ([email protected])",
"Accept": "application/xml"
}
});
clearTimeout(timeoutId)
if (!response.ok) {
console.log(response)
console.log(`HTTP Error: ${response.status} ${response.statusText}`)
return { error: "Failed to fetch from BGG" }
}
const xml = await response.text()
const parser = new DOMParser()
result = parser.parseFromString(xml, "text/xml")
const item = result.querySelector("item")
if (!item) {
return { error: "Game not found" }
}
return {
id: item.getAttribute("id"),
name: item.querySelector("name[type='primary']")?.getAttribute("value"),
yearPublished: item.querySelector("yearpublished")?.getAttribute("value"),
}
} catch (error) {
clearTimeout(timeoutId)
console.error("Fetch error:", error)
if (error.name === "AbortError") {
return { error: "Request timed out" }
}
return { error: "Internal server error: " + error.message }
}
}
the same code will work without any problem in browser, but i have to remove the token if i want the code to be executed perfectly. i have tried different approaches but noting helped. the code wont run in server.
I’m trying to fetch game data from the BoardGameGeek API. I’ve tried several approaches, both from the frontend and Node.js backend:
Using fetch from the frontend with Authorization: Bearer and User-Agent headers.
Adding Accept: application/xml and other headers recommended by BGG.
Using node-fetch in Node.js with the same headers.
Using the bgg-xml-api-client package in Node.js.
Verified that the API token is valid and not expired.
Despite this, I always get either:
CORS errors when calling from the frontend, or
403 Forbidden when calling from Node.js, even with correct headers.
I expected to be able to fetch game data from BGG API from my server without these errors.
Has anyone successfully fetched data from BGG API recently? Are there special requirements for browser requests or server requests with their token?