Look up Meals Using Database IDs

Learn how we can use the database IDs to look up meals.

We'll cover the following

TheMealDB API provides an endpoint with which we can search for the recipes for the meals using the database IDs. The base URI for this endpoint is https://www.themealdb.com/api/json/v1/1/lookup.php.

Note: The database IDs of the meals can be obtained using the endpoints that we discussed in the previous lesson.

Query parameter

This endpoint has only one query parameter, which is as follows:

Parameters

Type

Category

Description

i

integer

required

This is the query parameter used to search for a meal using its database ID.

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

Lookup a meal

The query parameter i, combined with the base URI of this endpoint, can be used to look up a meal using its ID. The code below demonstrates how we can get the meal recipe using the meal ID.

Press + to interact
import json
import requests
url=('https://www.themealdb.com/api/json/v1/1/lookup.php?i=52772')
#52772 is the ID for Teriyaki Chicken Casserole
response = requests.request("GET", url).json()
print(json.dumps(response, indent=4))

We’ll get the following information in response:

  • Ingredients required
  • Instructions to create a meal
  • Amounts of ingredients
  • Name of the meal
  • Database ID
  • Category
  • Cuisine
  • Link for an image of the meal
  • Video
  • Database tags
  • Last modified date
  • License

We can replace the ID 52772, in line 4, with the ID of any other meal to get its details.

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