How to filter query the database?

Avatar image for samueldev
samueldev

106

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#1  Edited By samueldev

For example,

  1. "I want a JSON representation of every game in the database where the Genre is FPS"

I thought the query for that would be something like,

"http://www.giantbomb.com/api/games/?api_key=[MY KEY]&format=JSON&genre=fps"

But that returns:

{

"error": "OK",

"limit": 100,

"offset": 0,

"number_of_page_results": 100,

"number_of_total_results": 42273,

"status_code": 1,

"results": [ array of 100 game objects ]

}

None of the objects in the results array even have a "genre" property, much less does it look like it's actually filtering properly.

  • How do I filter by genre, what would the query look like?

While we're at it:

  • How do I filter by release date, I.E. in a range, "between 1980 and 1990"?
  • How do I filter by giantbomb rating, I.E. "above 3 stars"?
  • How do I filter by whether or not GiantBomb has any videos uploaded for that game?

So many questions, so little API documentation with answers!

Avatar image for chaser324
chaser324

9415

Forum Posts

14945

Wiki Points

0

Followers

Reviews: 1

User Lists: 15

#2  Edited By chaser324  Moderator

Let's address these questions one at a time:

How do I filter by genre, what would the query look like?

You need to filter by the ID of the genre you want. To get these IDs, you can pull the list from the genres resource:

http://www.giantbomb.com/api/genres/?format=json&api_key=YOUR_API_KEY

In the case of FPS, the ID is 32. So, now you'll filter the games resource based on that ID:

http://www.giantbomb.com/api/games/?format=json&api_key=YOUR_API_KEY&filter=genres:32

The same basic principle of filtering by ID works in many other cases too.

EDIT: Unfortunately upon testing that, genres only shows up for a single game and not in the collection. I guess maybe you need to ask someone like @frobie, @mrpibb about possibly adding it.

How do I filter by release date, I.E. in a range, "between 1980 and 1990"?

Again, you should use filter, with a pipe between the two desired date values. You'll also likely want to use sort so that your results are in some logical order:

http://www.giantbomb.com/api/games/?format=json&api_key=YOUR_API_KEY&filter=original_release_date:1980-1-1 00:00:00|1990-1-1 00:00:00&sort=original_release_date:asc

How do I filter by giantbomb rating, I.E. "above 3 stars"?

I think the only way you can handle this is to filter on the reviews resource rather than games, and I'm not sure if it's possible to do a range.

Also, take note that review scores are identified by their percentage value out of 100 (i.e. one star = 20, two stars = 40, etc.)

Here's an example for getting all three star reviews:

http://www.giantbomb.com/api/reviews/?format=json&api_key=YOUR_API_KEY&filter=score:60

How do I filter by whether or not GiantBomb has any videos uploaded for that game?

I'm not sure that you're going to be able to do this filtering in the API call. You'll likely need to handle this filtering on your end. Also, the videos resource isn't appearing in results pulled from the games resource (the same issue noted above).

Avatar image for cogenthyena
CogentHyena

4

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#3  Edited By CogentHyena

@chaser324:

I've been trying to get a list of games filtered by multiple concepts that relate to them. As a test, I've tried http://www.giantbomb.com/api/games/?format=json&api_key=APIKEY&filter=concepts:4, but that seems to ignore the filter and just gives me 53,480 results, that certainly don't contain this concept (uber-trick system from SSX). Any tips?

Avatar image for chaser324
chaser324

9415

Forum Posts

14945

Wiki Points

0

Followers

Reviews: 1

User Lists: 15

#4  Edited By chaser324  Moderator

@cogenthyena: If you want a list of games that apply to a certain concept, you should just access the concept resource directly:

http://api.giantbomb.com/concept/4?format=jsonp&api_key=YOUR_API_KEY

Avatar image for cogenthyena
CogentHyena

4

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

@chaser324: Thank you! What if I want to search by multiple concepts at the same time? Is that possible? I could set up a loop that compares a series of individual concept queries, but it would be great if I could add multiple concepts directly into the API query.

Avatar image for chaser324
chaser324

9415

Forum Posts

14945

Wiki Points

0

Followers

Reviews: 1

User Lists: 15

#6 chaser324  Moderator

@cogenthyena: For at least the time being, I think you'll have to implement your own method of doing that. Maybe they'll add "concept" as a valid filter field at some point, but I don't know.

Avatar image for elchiconube
elchiconube

6

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

Hi! I have one more question about this. How about to filter games that names starts with 'gta' is it possible? Thanks!

Avatar image for laserhawk
LaserHawk

2

Forum Posts

0

Wiki Points

0

Followers

Reviews: 0

User Lists: 0

#8  Edited By LaserHawk

I have this EXACT same question. Any help would be greatly appreciated! I'm working on an android project I have to get done over the weekend, and I'm just trying to display a list of games based on genre. I can't seem to find the right URL to get that information.

The URL @chaser324 provided doesn't seem to work for me

http://www.giantbomb.com/api/games/?format=json&api_key=YOUR_API_KEY&filter=genres:32 Just gives me the same list of all games that I keep getting over and over like a curse. I've seen Desert Strike Advance at the top of my page like 100 times now. lol.

If I do this: https://www.giantbomb.com/api/genre/34/?api_key=API_KEY&format=json I just get back a response of a description of that genre etc.

Avatar image for chaser324
chaser324

9415

Forum Posts

14945

Wiki Points

0

Followers

Reviews: 1

User Lists: 15

#9  Edited By chaser324  Moderator

It looks like this data is unfortunately not easily accessible at the moment. I apologize for not checking if genre was a valid filter field when I posted that answer.

I think the only real solution here at the moment is to create a cache of all games in your own database so that you can properly do this query. Barring that, you'll need to make a request to the engineers to make games filterable based on genre.