Fetch the List of Available Filters

Learn how to get the lists of available categories, glasses, ingredients, and alcoholic filters in the database.

TheCocktailDB API provides us an endpoint to get the lists of items that can be used to filter the cocktails. The base URI of this endpoint is https://www.thecocktaildb.com/api/json/v1/1/list.php. This endpoint provides four types of lists:

  1. Categories list
  2. Glasses list
  3. Ingredients list
  4. Alcoholic filters list

Query parameters

We can use any of the following query parameters with this endpoint:

Parameters

Type

Category

Description

c

string

optional

This parameter is used to get all the available categories.

g

string

optional

This parameter gives us all the available glasses in the database.

i

string

optional

This parameter is used to get all available ingredients from the database.

a

string

optional

This parameter is used to get the list of available alcoholic filters.

We need to use at least one of these parameters with this endpoint. Calling it without any query parameters will return an error.

Get all the categories

The query parameter c is used to get the list of available categories. The value assigned to c will be list.

The widget below contains the code which fetches this list.

Press + to interact
import json
import requests
url=('https://www.thecocktaildb.com/api/json/v1/1/list.php?c=list')
response = requests.request("GET", url).json()
print(json.dumps(response, indent=4))
  • We import json and request packages in lines 1 and 2.
  • In line 4, we save the endpoint in a variable, url.
  • The API is called in line 5, and the response is saved in response.
  • The JSON output is printed in line 6.

Note: The code will stay the same throughout the course except for the endpoint.

We will get all available categories in response.

Get the list of available glasses

The query parameter g, when combined with https://www.thecocktaildb.com/api/json/v1/1/list.php, provides us the list of available glasses in the database. The value of g is list.

The code below demonstrates how we can get the list of available glasses.

Press + to interact
import json
import requests
url=('https://www.thecocktaildb.com/api/json/v1/1/list.php?g=list')
response = requests.request("GET", url).json()
print(json.dumps(response, indent=4))

We get all available glasses in response.

Get the list of available ingredients

The query parameter i, when combined with https://www.thecocktaildb.com/api/json/v1/1/list.php, provides us with the list of available ingredients in the database. The value of i is list.

The code below demonstrates how we can get the list of available ingredients.

Press + to interact
import json
import requests
url=('https://www.thecocktaildb.com/api/json/v1/1/list.php?i=list')
response = requests.request("GET", url).json()
print(json.dumps(response, indent=4))

We get all available ingredients in response.

Get the list of available alcoholic filters

The query parameter a combined with https://www.thecocktaildb.com/api/json/v1/1/list.php provides us with the list of available alcoholic filters in the database. The value of a is list.

The code below demonstrates how we can get the list of available alcoholic filters.

Press + to interact
import json
import requests
url=('https://www.thecocktaildb.com/api/json/v1/1/list.php?a=list')
response = requests.request("GET", url).json()
print(json.dumps(response, indent=4))

We get all available alcoholic filters in response.