More Requests
Requesting multiple things
To request multiple things, separate the ID numbers with commas:
You should see that in this XML document, there are two of the main <item> tags - one for each board game. We can write some quick code to print out the name of both of those games:
The results will look like this:
Requesting a user's game collection
There are a lot of parameters that you can add when requesting a user's collection. In this example, I've use some of the more common ones. The format for longer requests like this is as follows: the first parameter you list follows a ? (question mark), and each subsequent parameter follows an & (ampersand).
- username=samort7 - This is the user who's collection we are examining. In this case, we are looking at my collection.
- subtype=boardgame - This means that we are only interested in boardgames. We don't want to see boardgame expansions, accessories, videogames, etc.
- own=1 - This indicates that we only want to see games that I own. If the value was set to 0, that would mean 'false' and it would return games in my collection that I don't have marked as owned.
An interesting thing to note, is what happens after you send a request for a collection. Once a request is sent, the servers must catalog the items in a users collection, meaning your request won't be sent back right away. Instead, you will see something like this:
Once the log has been completed, you can run the query again and will receive the XML back. Unfortunately, there is no way to know how long it will take for that query to come back. If you get a 202 status code back, then it indicates BGG has queued your request and you need to keep retrying until you no longer get a 202 status code. You only have to ask for the log to be generated once. A new log won't be needed again unless the user changes their collection. If you want to parse the data to display the items in a users collection, you can do something like this:
The result will look like this:
And here's what the actual collection looks like on BGG:
Finding what's hot
You can easily see what the "hottest" things are on the 'Geek using the a variant of the following request:
Here's another quick script showing how you could utilize that XML to grab what's hot quickly:
Here's what the result would look like:
And here's where you would normally see that list on BGG's front page:
Doing a search
Without changing our last code snippet, we can actually do a search for games that match a specific criteria. For example, if we want to find all boardgames with 'dog' in the title, we can do the following:
Without changing our code, we'll get the following back: