Search for a Cocktail Recipe or Ingredient

We can search for the recipe of a cocktail or ingredient using the base URI www.thecocktaildb.com/api/json/v1/1/search.php.

Query parameters

We can use these query parameters with this endpoint:

Parameters

Type

Category

Description

s

string

optional

This parameter is used to search for the recipe of a cocktail using its name.

f

char

optional

This parameter is used to get a list of cocktails using the first letter of the name of the cocktails.

i

string

optional

This parameter is used to search for an ingredient using its name.

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

Search for the recipe of a cocktail

We search for the recipe of a cocktail using any of the following criteria:

  • By name
  • By the first letter of the name

Search for cocktail’s recipe by name

We use the query parameter s to search for the recipe of a cocktail using its name.

The code below contains the code where a cocktail is being searched using its name.

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

We get the following information in response:

  • Instructions to create the cocktail
  • Link to an image of the cocktail
  • Image attribution
  • Category of the cocktail
  • Ingredients required
  • Amounts of ingredients
  • Glass type
  • Tags
  • Drink ID
  • Drink specification (Alcoholic/Non-Alcoholic)
  • Name of the drink
  • Last modified date of the recipe
  • License (Yes/No)
  • Video

Note: Value of some of the response objects might be null depending on the availability of the data.

We can replace margarita in line 4 with the name of other cocktails, if we want the recipe for any other cocktail.

Search recipes of cocktails by the first letters of their names

We use query parameter f, with the base URL of the search endpoint, to get a list of cocktails whose names start with a similar letter. The code below shows how we can use this query parameter.

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

We’ll get the same information as the first case but for all the cocktails starting with the letter a.

We can replace a in line 4 with any other letter to get a different list.

Search for an ingredient

We use the query parameter i to search for an ingredient. The code below shows how to search for an ingredient.

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

We’ll get to know if the ingredient is alcoholic or not. We will also know the type, name, description, abbreviation, and database ID of the ingredient by calling this endpoint.

Note: Value of some of the response objects might be null depending on the availability of the data.

We can replace vodka in line 4 with any other ingredient we want to search for.