Creating a Meal Plan

Step by step guide for creating a meal plan

Before starting, you'll need to have a user created. Follow this guide to create one.

Getting Started

Suggestic meal plan API finds the best recipes for your user's dietary plan according to their food preferences and goals. The API has different services and parameters that let you specify how these meal plans are generated.

Let's start by generating a simple meal plan using the generateSimpleMealPlan mutation.

curl -XPOST 'https://production.suggestic.com/graphql' \
  -H 'Authorization: Bearer <User-JWT>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"query":"mutation { generateSimpleMealPlan { success message } }","variables":{}}'

Remember to replace <User-JWT> with your user's access token

Once the meal plan is created, you can request the meal plan using the mealPlan query.

curl -XPOST 'https://production.suggestic.com/graphql' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer Bearer <User-JWT>' \
  --data-raw '{"query":"{ mealPlan { day date calories meals { meal recipe { name } } } }"}'

The generateSimpleMealPlan mutation doesn't require any arguments. It generates a 7-days meal plan that complies with the user's program and preferences.

As you can see in the last response, generateSimpleMealPlan has series of default values, for example, each day has breakfast, lunch, dinner, and a single snack, with a daily caloric goal of 2000 kcal.

If you need more control over these settings, please review the Generate Meal Plan mutation.

Dates

Suggestic meal plan API always generates a 7-day plan.

Each day of the plan has a date. Day 1 has the date when the meal plan was generated, day 2 has the next date, and so on.

Meal Plan Lock

By default, generateSimpleMealPlan and generateMealPlan put a lock that stops the user from generating a new meal plan if one is in progress. In other words, a user can't generate a new meal plan if the current one still has dates in the future.

If you try using generateSimpleMealPlan, while a meal plan is in progress, you'll get the following response:

curl -XPOST 'https://production.suggestic.com/graphql' \
  -H 'Authorization: Bearer <User-JWT>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"query":"mutation { generateSimpleMealPlan { success message } }","variables":{}}'

To bypass the lock, send the argument ignoreLock: true .

curl -XPOST 'https://production.suggestic.com/graphql' \
  -H 'Authorization: Bearer <User-JWT>' \
  -H 'Content-Type: application/json' \
  --data-raw '{"query":"mutation { generateSimpleMealPlan(ignoreLock: true) { success message } }","variables":{}}'

Customization and configuration

You can think of meal plan generation as a two stages process.

In the first stage, the planner finds a set of recipes that are good candidates for a personalized meal plan. These recipes are a good choice according to the user's restrictions, dietary program, and custom attributes. This is the customization stage.

You can learn more about how to set users personal restrictions, subscribing users to programs, and setting their custom attributes as follows:

How to apply restrictions to a meal plan

Refer to the User's Restrictions page.

Restrictions can be added in the following scenarios:

  • Before generating a meal plan: Define which restrictions you need to apply, and then the meal plan is generated based on the applied restrictions.

  • During a meal plan in progress: It may be the case where new restrictions need to be applied to the meal plan in progress. In this case, apply these new restrictions and generate the meal plan again.

If the meal plan is finished by the time the restrictions are set, a new 7 day meal plan will be generated where these new restrictions will be applied.

How to subscribe users to a specific program

Refer to the User's Program page.

To add a program, update the User Program and then generate the meal plan.

How to add custom attributes

Refer to the User's Custom Attributes page.

The second stage is configuration. Configurations are sent to the meal planner in each query as parameters and are used to sort and group the recipes into daily plans. This includes grouping constraints, like setting the daily caloric goals, the number of snacks per day, or the minimum serving weight in grams per meal.

Learn more about these configurations in the generateMealPlan page.

You can change configurations and customize as much as you need depending on your app and use cases.

Common Errors

When users have too many restrictions and the meal plan is not capable of generating a whole week of the meal plan, the following error is displayed:

"generateMealPlan":

    "success": false,
    "message": "Couldn't generate a meal plan with the current settings."
 }

This error may appear due to:

  • There is a problem with the definition of macro values. Check your user's meal plan settings

  • The type of subscription.

  • The user program.

For more information, refer to this documentation.

More about meal plans

  • Read about user restrictions, programs, and custom attributes to customize a meal plan.

  • Meal plans are not automatically generated when a user's program, restrictions, or attributes change. Read more about keeping a meal plan updated on the generateMealPlan page.

  • The mealPlan response can include fields that are not used here to keep the examples simple. See a full list of fields on the meal plan query page.

  • Take a look at the custom meal plan query. It lets you request meal plans without assigning them to the user. You can request as many as you need and can help you find the configuration that works best for your app and use cases.

Last updated