Skip to content

Find a game despite typos

People type game names badly, in their own language, and with the punctuation left out. Two endpoints cover it:

GET /search GET /suggest
For a results page a search box, at every key press
Returns games (and, with type=all, people and publishers in terms) games and up to 3 people or publishers
Paging page or cursor none: one short list
Answer full GameSummary objects a slimmer Suggestion, with thumbnail
Terminal window
curl "https://api.thebgdb.org/v1/search?q=brass%20birmigham"
  • Every word, any order, any name. A game matches when one of its names (the main one or an alternate one, in any language) contains every word of q. Case, accents and punctuation are ignored: flugelschlag finds Flügelschlag, catan! finds Catan.
  • Misspellings. When fewer than limit games match as written, games with a close name are added after them, each marked approximate: true. cattan finds Catan, wingspn finds Wingspan. Show these as “Did you mean…” if your interface tells them apart.
  • Which name matched. matchedName says which alternate name was found when it was not the main one, so you can show “Die Siedler von Catan (Catan)”.
  • Order. A name equal to the query first, then names starting with it, then a word starting with it, then names containing it; within each, the better-known games first.

Send lang (a BCP 47 code such as fr, ja or pt-BR):

Terminal window
curl "https://api.thebgdb.org/v1/search?q=aventuriers&lang=fr"

A game with a name in that language comes back with it as name, and its main name as originalName. A regional code falls back on its language (fr-CA on fr).

limit sets the page size. Go on with the nextCursor of the previous answer as cursor, or ask for a numbered page:

Terminal window
curl "https://api.thebgdb.org/v1/search?q=catan&limit=24&page=2"

Send one of page or cursor, not both (invalid_page). A page past the last is refused with page_out_of_range.

type=people finds designers and artists, type=publishers publishers, and type=all games plus up to 10 people and publishers in terms on the first page:

Terminal window
curl "https://api.thebgdb.org/v1/search?q=feld&type=people"

GET /suggest answers in a few milliseconds from the search index, with the same matching and order:

Terminal window
curl "https://api.thebgdb.org/v1/suggest?q=wings&lang=en"

Each game carries its thumbnail (our small copy of the cover), so the list can show covers at once. Designers, artists and publishers come back with their kind. Call it as the person types, after a short pause (150 to 250 ms) so a fast typist does not send a request per letter.

async function findGames(query: string, lang = "en") {
const url = new URL("https://api.thebgdb.org/v1/search");
url.searchParams.set("q", query);
url.searchParams.set("lang", lang);
const response = await fetch(url);
if (!response.ok) throw new Error((await response.json()).code);
const { data } = await response.json();
return data.map((game) => ({
slug: game.slug,
name: game.name,
guessed: game.approximate === true,
}));
}
import requests
def find_games(query, lang="en"):
response = requests.get(
"https://api.thebgdb.org/v1/search",
params={"q": query, "lang": lang},
timeout=10,
)
body = response.json()
if not response.ok:
raise RuntimeError(body["code"])
return [(g["slug"], g["name"], g.get("approximate", False)) for g in body["data"]]