Look Up Meals Using API-Assigned IDs

Learn how we can use the API-assigned IDs to look up meals.

We can use the API-assigned IDs of meals to access recipes for meals directly. In this lesson, we’ll look at how to use these IDs to fetch recipes.

Fetch required info using ID

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

Request parameter

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

Parameters

Type

Category

Description

i

Integer

Required

Used to search for a meal using its API-assigned ID

Note: We can use the endpoint discussed in the previous lesson to obtain the API-assigned IDs of the meals.

The query parameter, i, combined with the base URI of this endpoint, can be used to look up a meal using its ID.

Press + to interact
const endpointUrl = new URL('https://www.themealdb.com/api/json/v1/1/lookup.php');
const queryParameters = new URLSearchParams({
i: '52772' // 52772 is the ID for Teriyaki Chicken Casserole
});
const options = {
method: 'GET'
};
async function fetchMealByID() {
try {
endpointUrl.search = queryParameters;
const response = await fetch(endpointUrl, options);
printResponse(response);
}
catch (error) {
printError(error);
}
}
fetchMealByID();

Here is a brief explanation of the above code:

  • Line 1: We define the URL of the endpoint.
  • Lines 3–9: We define the query parameter and HTTP request type to call the endpoint.
  • Lines 11–21: We define the fetchMealbyID() function that calls the endpoint and prints the response.
  • Line 23: We call the fetchMealbyID() function.

We can replace the 52772 ID, in line 4, with the ID of any other meal to get its details. Try using the IDs in the table below to get the recipes for the meals listed.

Meal

API-assigned ID

Honey Teriyaki Salmon

52773

Breakfast Potatoes

52965

Nanaimo Bars

52924

Chicken & mushroom Hotpot

52846

Sugar Pie

52931

Response fields

The table below contains some important response fields:

Response field

Type

Description

idMeal

Integer

The API-assigned ID of the meal

strMeal

String

The name of the meal retrieved by this endpoint

strCategory

String

The category of the meal

strInstructions

String

The instructions to prepare the meal

strMealThumb

String

A link for the image of the meal

strIngredient1 - strIngredient20

String

The names of the required ingredients to make the meal

strMeasure1-strMeasure20

String

The amount of ingredients required to make the meal

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