Games ~ BoardGameGeek (BGG) API - uchicago-cs/chigame GitHub Wiki

Using the BoardGameGeek (BGG) API

We plan to use the information from BGG to assist admins when they create games.

Official API Documentation and Guides

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/

Getting a list of games

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

Getting information on a game

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

Handling the XML Response

The BGG API returns XML, not JSON, so we need to handle responses slightly differently.

JS

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);
    });

Python

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
⚠️ **GitHub.com Fallback** ⚠️