twitchtv / igdb-api-python

Python wrapper for IGDB API version 4
MIT License
74 stars 9 forks source link

[SOLVED] Support for Multi-querying #38

Closed BertrandToulas closed 4 months ago

BertrandToulas commented 4 months ago

[EDIT] Problem solved, see next comment.

I've tried several ways to format my code to try and make multi-querying work, but they all result in a HTTPError: 400 Client Error: Bad Request for url: https://api.igdb.com/v4/multiquery error. Looking into the repo files, multi-querying doesn't seem to be implemented at the moment.

Is support planned?

In the meantime, thank you for the work!

BertrandToulas commented 4 months ago

Nevermind, my requests were improperly formatted. It's working now. Here's how you could go about querying the first 1,000 rows of the games table (given that a single query is limited to 500):

wrapper = IGDBWrapper(client_id, access_token)
data = wrapper.api_request('multiquery',
                                  'query games "Query 1" {fields *; where id >= 0 & id < 500; limit 500;}; \
                                  query games "Query 2" {fields *; where id >= 500 & id < 1000; limit 500;};'
)

It can get a bit unwieldy if you need to use formatted strings with variables because of all the single and double curly braces you'll need to deal with, but it works! For example:

data = wrapper.api_request('multiquery',
                                  f'query games "Query 1" {{fields *; where id >= 0 & id < 500; limit {MAX_ROWS_PER_REQUEST};}}; \
                                  query games "Query 2" {{fields *; where id >= 500 & id < 1000; limit {MAX_ROWS_PER_REQUEST};}};'
)
BertrandToulas commented 4 months ago

Multi-queries are already supported, found the correct syntax to make them work.