# How to log your custom recipe

## Overview

Custom recipes is a great way to quickly enter meals into your diary, they let you save food with multiple ingredients so you can quickly add it to your daily log. So, instead of adding individual food you eat at breakfast daily, you can create a "My Breakfast routine" recipe with all of these ingredients. So you time consuming will be way far better.

In this example, you will see how to create and log your custom recipe.

### Requirements&#x20;

* To have your own common or branded food created (not mandatory)

### API endpoints to use

Through the example, use the following endpoints in the same order as they are listed below:&#x20;

* [`commonFoods`](https://docs.suggestic.com/graphql/query/search/food-search-for-food-log/common-foods-search) and/or [`brandedFoods`](https://docs.suggestic.com/graphql/query/search/food-search-for-food-log/branded-foods-search#available-fields) to get the food Id, either for existing common or branded food.
* [`createMyCommonFoods`](https://docs.suggestic.com/graphql/query/mutations/food-log/log-entries/create-my-common-foods) and/or [`createMyBrandedFoods`](https://docs.suggestic.com/graphql/query/mutations/food-log/users-foods-and-recipes/create-my-branded-food) if you need to add a specific food to create your recipe.
* [`myCommonFoods`](https://docs.suggestic.com/graphql/query/search/food-search-for-food-log/my-common-foods-search) or [`MyBrandedFoods`](https://docs.suggestic.com/graphql/query/search/food-search-for-food-log/my-branded-food-search) to get the `FoodId` already added. Use this in the `createMyRecipe` mutatio&#x6E;**.**
* [`createMyRecipe`](https://docs.suggestic.com/graphql/query/mutations/food-log/users-foods-and-recipes/create-a-user-recipe) by using the `FoodId` gathered before.
* [`myRecipes`](https://docs.suggestic.com/graphql/query/queries/food-log/users-foods-and-recipes/users-recipes) to list the recent recipe created and get its id to log it. *(Optional Step)*
* [`createMealLog`](https://docs.suggestic.com/graphql/query/mutations/food-log/log-entries/meal-log-legacy/food-logs)  mutation to log your meal based on the recipe you created above.

## Code Example

Find all the steps detailed below in this [graphqlbin](https://graphqlbin.com/v2/XVNxFD). Modify the code accordingly.

## Example

**Name of the recipe:** *<mark style="background-color:yellow;">Vegan Milkshake</mark>*

Follow the 5 steps below to create the Vegan Milkshake recipe to be then logged into your dairy:&#x20;

<details>

<summary><strong>STEP 1:  Find the foods to add to your recipe</strong></summary>

In the case of this example, use the `commonFoods` to find the "*Vanilla extract*".

**Request:**

```graphql
{
  commonFoods(query: "vanilla extract", first:1) {
    edges {
      node {
        id
        name
        nutrients {
          type
          amount
          name
          unit
        }
      }
    }
  }
}
```

**Response**

```graphql
{
  "data": {
    "commonFoods": {
      "edges": [
        {
          "node": {
            "id": "Q29tbW9uRm9vZE5vZGU6YzYwZDljOWYtM2IyMy00ZTQxLWE3NDYtNDE2NmE4NzZhMjkz",
            "name": "Vanilla extract",
            "nutrients": [
              {
                "type": "CALCIUM_CA",
                "amount": 11,
                "name": "Calcium, Ca",
                "unit": "MG"
              },
              {
                "type": "POTASSIUM_K",
                "amount": 148,
                "name": "Potassium, K",
                "unit": "MG"
              },
              {
                "type": "ZINC_ZN",
                "amount": 0.11,
                "name": "Zinc, Zn",
                "unit": "MG"
              },
              {
                "type": "NIACIN",
                "amount": 0.425,
                "name": "Niacin",
                "unit": "MG"
              },
              {
                "type": "PANTOTHENIC_ACID",
                "amount": 0.035,
                "name": "Pantothenic acid",
                "unit": "MG"
              },
              {
                "type": "VITAMIN_B_6",
                "amount": 0.026,
                "name": "Vitamin B-6",
                "unit": "MG"
              },
              {
                "type": "FAT",
                "amount": 0.06,
                "name": "Total lipid (fat)",
                "unit": "G"
              },
              {
                "type": "CARBS",
                "amount": 12.65,
                "name": "Carbohydrate, by difference",
                "unit": "G"
              },
              {
                "type": "ENERGY",
                "amount": 288,
                "name": "Energy",
                "unit": "KCAL"
              },
              {
                "type": "WATER",
                "amount": 52.58,
                "name": "Water",
                "unit": "G"
              },
              {
                "type": "PROTEIN",
                "amount": 0.06,
                "name": "Protein",
                "unit": "G"
              },
              {
                "type": "ASH",
                "amount": 0.26,
                "name": "Ash",
                "unit": "G"
              },
              {
                "type": "ALCOHOL_ETHYL",
                "amount": 34.4,
                "name": "Alcohol, ethyl",
                "unit": "G"
              },
              {
                "type": "FIBER_TOTAL_DIETARY",
                "amount": 0,
                "name": "Fiber, total dietary",
                "unit": "G"
              },
              {
                "type": "IRON_FE",
                "amount": 0.12,
                "name": "Iron, Fe",
                "unit": "MG"
              },
              {
                "type": "MAGNESIUM",
                "amount": 12,
                "name": "Magnesium, Mg",
                "unit": "MG"
              },
              {
                "type": "PHOSPHORUS_P",
                "amount": 6,
                "name": "Phosphorus, P",
                "unit": "MG"
              },
              {
                "type": "SODIUM_NA",
                "amount": 9,
                "name": "Sodium, Na",
                "unit": "MG"
              },
              {
                "type": "COPPER_CU",
                "amount": 0.072,
                "name": "Copper, Cu",
                "unit": "MG"
              },
              {
                "type": "MANGANESE_MN",
                "amount": 0.23,
                "name": "Manganese, Mn",
                "unit": "MG"
              },
              {
                "type": "VITAMIN_A_IU",
                "amount": 0,
                "name": "Vitamin A, IU",
                "unit": "IU"
              },
              {
                "type": "DHA",
                "amount": 0,
                "name": "22:6 n-3 (DHA)",
                "unit": "G"
              },
              {
                "type": "EPA",
                "amount": 0,
                "name": "20:5 n-3 (EPA)",
                "unit": "G"
              },
              {
                "type": "DPA",
                "amount": 0,
                "name": "22:5 n-3 (DPA)",
                "unit": "G"
              }
            ]
          }
        }
      ]
    }
  }
}
```

`FoodID` to copy --> `Q29tbW9uRm9vZE5vZGU6YzYwZDljOWYtM2IyMy00ZTQxLWE3NDYtNDE2NmE4NzZhMjkz`

</details>

<details>

<summary>STEP 2: Create a specific food</summary>

In case you need to create a specific food, execute the `createMyCommonFoods` or `createMyBrandedFoods`. In the example below, we will create the "Vegan vanilla ice cream" common food:

```graphql
mutation createMyCommonFoods {
  createMyCommonFoods(
    input: {
      name: "Vegan vanilla ice cream"
      description: "vegan vanilla ice cream"
      nutrients: [
        { amount: 124, unit: "MG", nutrient: SODIUM_NA }
        { amount: 124, unit: "MG", nutrient: POTASSIUM_K }
      ]
      portions: [{ amount: 45.33, unit: "G", gramWeight: 1 }]
    }
  ) {
    success
    message
  }
}
```

</details>

<details>

<summary>STEP 3: Find your created foods</summary>

Find the foods to include in your recipe. Execute the `myCommonFoods` or `myBrandedFoods` queries to find them. In the case of this example, use the `myCommonFoods` to find your already created ingredient which is the "*Vegan vanilla ice cream*".

**Request:**

```graphql
{
  myCommonFoods {
    edges {
      node {
        id
        name
        nutrients{
          name
          type
          unit
          amount
        }
      }
    }
  }
}
```

**Response:**

```graphql
{
  "data": {
    "myCommonFoods": {
      "edges": [
        {
          "node": {
            "id": "TXlDb21tb25Gb29kOjNpR2RjSUFCYjREdGhOVmFDQWpI",
            "name": "Vegan vanilla ice cream",
            "nutrients": [
              {
                "name": "Sodium, Na",
                "type": "SODIUM_NA",
                "unit": "MG",
                "amount": 124
              },
              {
                "name": "Potassium, K",
                "type": "POTASSIUM_K",
                "unit": "MG",
                "amount": 124
              }
            ]
          }
        },
      ]
    }
  }
}
```

From the response, copy the `FoodId` -> `TXlDb21tb25Gb29kOjNpR2RjSUFCYjREdGhOVmFDQWpI`

*Each ID is different so make sure to copy the Id retrieved in your query response.*

Use this query as many times as necessary until you find all the foods the recipe is required to have. See step 2 in case you need to create your food.

</details>

<details>

<summary><strong>STEP 4: Create your own recipe</strong></summary>

Use the Food IDs created previously to create your own recipe:

**Request:**

```graphql
mutation createMyRecipe {
  createMyRecipe(
    input: {
      name: "Vegan Milkshake"
      tags: ["Vegan", "Snack"]
      ingredientLines: ["Almond Milk", "Vegan vanilla ice cream"]
      ingredients: [
        { foodId: "TXlDb21tb25Gb29kOjNpR2RjSUFCYjREdGhOVmFDQWpI", grams: 10},
        { foodId: "Q29tbW9uRm9vZE5vZGU6YzYwZDljOWYtM2IyMy00ZTQxLWE3NDYtNDE2NmE4NzZhMjkz", grams: 120}
      ]
      numberOfServings: 1
      mealTimes: [BREAKFAST, SNACK]
      courses: "Snack"
      instructions: "Put all ingredients on Blender"
    }
  ) {
    success
    message
     recipe { id name }
  }
}
```

**Response:**

```graphql
{
  "data": {
    "createMyRecipe": {
      "success": true,
      "message": "My recipe has been saved",
      "recipe": {
        "id": "VXNlclJlY2lwZTpQeDFSZTN3QlY0Q1V6aWdSV2VqcQ==",
        "name": "Vegan Milkshake"
      }
    }
  }
}
```

Copy the "ID" retrieved from the recipe created to log the meal.

**Optional:** If you cannot get the "ID", you can execute the [`myRecipes`](https://docs.suggestic.com/graphql/query/queries/food-log/users-foods-and-recipes/users-recipes) query to get it.

</details>

<details>

<summary>STEP 5: Log your meal </summary>

Finally, log the meal based on your own recipe created:

**Request:**

```graphql
mutation {
  addFoodLog (date:"2021-10-02", 
  foodId: "VXNlclJlY2lwZTpQeDFSZTN3QlY0Q1V6aWdSV2VqcQ==", 
  mealTime:SNACK,
  servings:2,)
    {
      success
      message
    }
  }
```

**Response:**

```graphql
{
  "data": {
    "addFoodLog": {
      "success": true,
      "message": "Food log saved"
    }
  }
}
```

</details>
