Open Trivia Database API Bug

Hi All,

I am writing a project to use the opentdb.com api, that asks the a user for difficulty then category, but the is no option for the API to return all questions of that difficulty / category combination.

This is very strange thing, as I had assumed not supplying an ‘amout’ parameter would return all. Is there a specific ‘amount’ value I can supply so that it returns all of the questions or it is not something that can be done? If I set it to 50, it only returns questions for a category that has more than total.

Is there something that I am doing wrong?

Thanks

Stef

There is a maximum amount of 50 questions that can be requested from each API call. There is no mechanism for retrieving all the trivia questions in database for a particular query.

The amount value also needs to be passed to the API call.

Thank you for the response, but that doesn’t really answer my question. If I ask the API for 50 questions for a difficulty / category combo, and there isn’t 50 questions, I get nothing. There is no way of telling how many questions belong to a category. In each case I want as many as I can so that the user can have a decent trivia run, but if my API call doesn’t give a response, I can’t show the user anything. Therefore how can I make a request for a total number of questions, if I don’t know how many there are? Surely you understand my point. Is there anyway of knowing how many questions there are so I can request the correct amount, if there are less than 50?

There is no API call to get how many questions exist in a category, but that might be an interesting addition for me to implement in the future.

As a developer myself, considering you are using a basic .php script with GET parameters, surely such an addition would take 5 minutes? Why would it take you more than that to test the value of a &questions=total parameter? As it is I will have to do a API call with an increasing number for each difficulty / category until I get no results, and then know the amount I can call for, even hold all the questions locally if necessary.

I wanted to preface this with a little note. While we allow anyone to use our database in their products via our API, first and foremost the database is designed for use by PixelTail Games, specifically for Tower Unite. What this boils down to, is that features are really only added to the database when we need them ourselves. I also wanted to note, that while it wasn’t hard to implement this, nor did it take a lot of time, it was 12:50AM in my region when I posted my note about future implementation.

That being said, I have created two API calls that can be used to retrieve the number of questions in the database.


The first API call I created was “count”, and it can be used like so.
https://opentdb.com/api_count.php?category=VALID_CATEGORY_ID_HERE

Here’s an example snippet of what it’ll return:

{
  "category_id": 9,
  "category_question_count": {
    "total_question_count": 182,
    "total_easy_question_count": 69,
    "total_medium_question_count": 81,
    "total_hard_question_count": 32
  }
}

The second API call I created was “count_global”, and can be used like so.
https://opentdb.com/api_count_global.php

Here’s an example snippet of what it’ll return:

{
  "overall": {
    "total_num_of_questions": 4166,
    "total_num_of_pending_questions": 550,
    "total_num_of_verified_questions": 2595,
    "total_num_of_rejected_questions": 1021
  },
  "categories": {
    "9": {
      "total_num_of_questions": 483,
      "total_num_of_pending_questions": 84,
      "total_num_of_verified_questions": 182,
      "total_num_of_rejected_questions": 217
    },

I’ve also updated the API documentation to contain these calls.

Hopefully these will be of use to you, and I wish you the best in developing your Trivia application.

2 Likes

Thank you very much my friend. Of course it is a free service, and I am very happy that you provide it to us. I am sure this has added to your work load, but I think it is very nice peice of information to know.

1 Like

How to retrieve the number of questions in the database based on TYPE? for example i’d like to know how many verified and pending questions based on boolean type.