Server possibly returning incorrect response code

Hey, first of all thanks a lot for running the Open Trivia DB. I’ve been working on an Android Trivia App and it seems that either I am doing something wrong (which is definitely possible) or there’s a bug in the server code.

To be precise, when requesting a set of questions from a specific category with a specific difficulty and specific amount which exceeds the amount of questions available on the server, the expected response code is Code 1: No Results Could not return results. The API doesn’t have enough questions for your query. (Ex. Asking for 50 Questions in a Category that only has 20.)

This actually works as expected, only if you do NOT specify a token

When you perform the above kind of request including a token, the server will return a response code Code 4: Token Empty Session Token has returned all possible questions for the specified query. Resetting the Token is necessary.

So that means anybody with a valid session token will be performing a request to reset the token and then … repeat the request performed previously, leading to an infinite loop.

If a token is supplied and the category simply does not have enough questions after applying the other restrictions (difficulty and amount) the server should return Code 1 ?

Hi ByteTonight, thanks for using our API and I wish you success with your Trivia App.

I can try to explain the reason the two codes appear. Currently, the only reason Code 1 would ever be returned is that we don’t have enough questions to satisfy the query. This is due to the fact that we aren’t bursting at the seams with trivia questions. In the future, where we have perhaps even triple the amount of questions we have now, the Code 1 issue shouldn’t come up often if ever.

What’s going on, is that when using a Token, the API assumes that because no questions could be returned, the Token has dried up its pool of potential questions, so it returns a Code 4. Sadly, the same solution is the same for Code 1, if we had more questions to satisfy the queries, then in the future Code 4 would return via it’s intended state.

So the issue isn’t really on your side at all, and the only reason the API is acting how it is is because we don’t currently have enough questions to satisfy every potential query (50 questions, any category, any difficulty, any question type). To fix the infinite loop, you could back out of the query if the token has to be reset more than three times or something like that for the mean time.

Thanks again for your post, and feel free to ask any more questions you have.

Hi @Caboose700, thanks for confirming the issue. I’ll try your suggestion for now.