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

Getting 400 Error Code #42

Closed iamphoenix310 closed 4 years ago

iamphoenix310 commented 4 years ago

Hi,

I am trying to fetch the sample code but it's returning (400 Bad Request) error code. Here's my code:

const igdb = require('igdb-api-node').default;
const apicalypse = require('apicalypse')
const client = igdb('my-key');

async function queryMode() {
    const response = await client
    .fields('name,age_rating,platforms')
    .limit(5)
    .offset(100)
    .sort('name')
    // important bit here
    .where('platforms.category = 6')
    .request('/games')

return response.data;
}

queryMode().then((data) => {
    console.log(data)
}).catch((e) => {
    console.log(e)
})
iamphoenix310 commented 4 years ago

The following code is working now.

async function main () {
    try {
      // const where = 'release_dates.platform = (6)'
      const where = '(platforms = [6,48] & genres = 13) | (platforms = [130,48] & genres = 12)'
      const response = await client
        .fields('name')
        .limit(20)
        .offset(0)
        .where(where)
        .request('/games')
      console.log(response.data)
    } catch (error) {
      console.log(error)
    }
  }
  main()