Creating a Meal Plan
Step by step guide for creating a meal plan
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. Request
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":{}}'
{
"data": {
"generateSimpleMealPlan": {
"success": true,
"message": "Meal plan was successfully created"
}
}
}
Remember to replace
<User-JWT>
with your user's access tokenOnce the meal plan is created, you can request the meal plan using the
mealPlan
query.Request
Response
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 } } } }"}'
{
"data": {
"mealPlan": [
{
"day": 7,
"date": "2021-03-15 02:00:00+00:00",
"calories": 1966.93596472514,
"meals": [
{
"meal": "breakfast",
"recipe": {
"name": "Chocolate Collagen Keto Granola"
}
},
{
"meal": "dinner",
"recipe": {
"name": "Pan-Seared Salmon And Roasted Vegetables"
}
},
{
"meal": "lunch",
"recipe": {
"name": "Layered Bean Dip"
}
},
{
"meal": "snack",
"recipe": {
"name": "Celery With Cream Cheese"
}
}
]
},
[...]
{
"day": 1,
"date": "2021-03-09 02:00:00+00:00",
"calories": 2028.06644439517,
"meals": [
{
"meal": "breakfast",
"recipe": {
"name": "Scotch Eggs"
}
},
{
"meal": "dinner",
"recipe": {
"name": "Turmero Onion Burgers"
}
},
{
"meal": "lunch",
"recipe": {
"name": "Herb-Seasoned Sheperd'S Pie"
}
},
{
"meal": "snack",
"recipe": {
"name": "Seasoned Roasted Carrots"
}
}
]
}
]
}
}
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.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.
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:Request
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":{}}'
{
"data": {
"generateSimpleMealPlan": {
"success": false,
"message": "User has a meal plan in progress."
}
}
}
To bypass the lock, send the argument
ignoreLock: true
.Request
Response
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":{}}'
{
"data": {
"generateSimpleMealPlan": {
"success": true,
"message": "Meal plan was successfully created"
}
}
}
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:
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.
To add a program, update the User Program and then generate the meal plan.
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.
You can change configurations and customize as much as you need depending on your app and use cases.
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:
- The type of subscription.
- The user program.
- 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 modified 7mo ago