Games ~ BoardGameGeek (BGG) API - uchicago-cs/chigame GitHub Wiki
We plan to use the information from BGG to assist admins when they create games.
The official documentation: https://boardgamegeek.com/wiki/page/BGG_XML_API2
A useful guide someone put together: http://www.tayloraliss.com/bggapi/
All calls use the following base url:
https://www.boardgamegeek.com/xmlapi2/
Returns all games with <search_term>
contained in their name, sorted alphabetically:
/search?type=boardgame&query=<search_term>
We can require that the result exactly match the search term:
/search?type=boardgame&exact=1&query=<search_term>
Get a list of the hottest boardgames on the site:
/hot?boardgame
Example response: https://www.boardgamegeek.com/xmlapi2/search?type=boardgame&query=catan
Returns the listing information for the game with id equal to <bgg_id>
:
/thing?id=<bgg_id>
We can get extra information on ratings and other statistics by adding stats=1
:
/thing?id=<bgg_id>&stats=1
Example response: https://www.boardgamegeek.com/xmlapi2/thing?id=13&stats=1
The BGG API returns XML, not JSON, so we need to handle responses slightly differently.
fetch(url)
.then(response => response.text())
.then(data => {
let parser = new DOMParser();
let xmlDoc = parser.parseFromString(data, "text/xml");
let name = xmlDoc.querySelector('name').getAttribute('value');
let image = xmlDoc.querySelector('image').textContent;
let description = xmlDoc.querySelector('description').textContent;
}).catch(error => {
console.error('Error:', error);
});
import requests
import xml.etree.ElementTree as ET
response = requests.get(url)
root = ET.fromstring(response.text)
name = root.find(".//name").get("value")
image = root.find(".//image").text
description = root.find(".//description").text