twitchtv / igdb-api-node

Nodejs Wrapper for IGDB.com API. Requires an API key. Get one at:
https://api.igdb.com/
MIT License
128 stars 15 forks source link

Problem getting filters applied #32

Closed cedmax closed 5 years ago

cedmax commented 5 years ago

I hope this is not a duplicate: I checked the closed issues related to filtering but none of them seems to be exactly what I'm looking for.

I'm trying to query sorting by aggregated_rating, but filtering whatever games has less than 10 reviews.

I tried this

await client.games({
    fields: "*",
    order: "aggregated_rating:desc",
    filters: {
      "aggregated_rating_count.gt": 10,
    },
})

but the endpoint hit was https://api-endpoint.igdb.com/games/?fields=*&order=aggregated_rating:desc&filter[aggregated_rating_count.gt]=10 and the filter didn't get applied as it should have filter[aggregated_rating_count][gt]=10 for it to work as expected.

I couldn't find any way to make it happen but changing my filters to

 filters: {
    "aggregated_rating_count][gt": 10,
 },

which is rather ugly. Am I missing something?

krazyjakee commented 5 years ago

Not sure where you got the full stop from.

From docs:

client.games({
    filters: {
        'release_dates.date-gt': '2010-12-31',
        'release_dates.date-lt': '2012-01-01'
    },
    limit: 5,
    offset: 0,
    order: 'release_dates.date:desc',
    search: 'zelda'
}, [
    'name',
    'release_dates.date',
    'rating',
    'hypes',
    'cover'
]).then(log);

So your code should be...

await client.games({
    fields: "*",
    order: "aggregated_rating:desc",
    filters: {
      "aggregated_rating_count-gt": 10,
    },
})
cedmax commented 5 years ago

🤦‍♂️ I think I got confused by the nested property .date-gt, thanks