Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The Trustwell Genesis Foods API provides a powerful way to access food data, perform analyses, query standard entities, and create new ingredients or recipes. Built on GraphQL, the API allows you to define precisely what data you need and retrieve it efficiently. This guide will walk you through how to authenticate and start making queries and mutations using the API.

Obtaining your API Key

Note
  • Only Administrators with API Access will have the ability to generate an API Key.

  • Treat your API Key like a password. Keep it secret; keep it safe.

  • For questions, please contact Trustwell Support

To start using the Genesis Foods API, follow these steps:

  1. Log into the Genesis Foods application.

  2. Generate an API Key.

    1. Only Administrators with API Access will have the ability to generate an API Key.

  3. Include this API Key .

  4. In the lower left, click the vertical ellipsis next to your Organization Name / Username.

  5. Select Profile.

    image-20241010-225201.pngImage Added
  6. Select API Tokens along the top.

    image-20241010-225301.pngImage Added
  7. Click Create API Token.

  8. Enter a Label.

  9. Click Create Token.

  10. Once created, we recommend using the Copy button to copy the string to the clipboard. image-20241010-230028.pngImage Added

    • Important: This is the only time you will be able to obtain this Token. Should this be lost, the Token should be deleted and a new one created.

    • Preserve this Token string as you would other secrets / passwords.

  11. Include this API Key in the request headers for every request you make.

...

  • The API enforces rate and usage limits.

  • Requests are only processed over HTTPS. HTTP requests will be redirected to the corresponding HTTPS resource.

  • The Genesis Foods API uses GraphQL and has a single endpoint. For more information on how GraphQL works, please visit http https://graphql.org/.

Authentication/Authorization

You can generate an API Key through the Genesis Foods application, provided your user has the necessary permissions. If you do not have access to generate API Keys, please contact your Account Manager Trustwell Support for assistance.

Include your API Key in the request headers

Code Block
{ 
  "X-API-KEY": "XXXYYYYBBBBZZZZ" 
}


API Reference Documentation

The Genesis Foods GraphQL API reference documentation.

https://docs.trustwell.com/genesis/api/

API Playground

The Genesis Foods GraphQL API Playground with example code.

Genesis Foods GraphQL API Playground

https://github.com/esha/genesis-foods-api-playground

API Operations: Queries and Mutations Examples

The Trustwell Genesis Foods API offers a range of operations that allow you to interact with the system through both queries and mutations. Queries enable you to fetch data, such as searching for foods or retrieving nutritional analysis, while mutations allow you to create or update data, like adding ingredients or recipes. Each operation is designed to be flexible and powerful, giving you control over the specific data you need and minimizing unnecessary overhead.

Below are examples of common API operations, showing how to construct requests and handle responses for both queries and mutations.

Info

Genesis GraphQL API URLEndpoint

Production: https://api.trustwell.com/genesis

Preview: TBD https://api-preview.trustwell.com/genesis

In the examples below, many responses have been truncated for readability.

...

Searching for foods is a key action that users utilize to build recipes.

Search results are paginated.

...

Expand
titleRequest

Query

query($input: FoodSearchInput!){ foods{
Code Block
languagejson
Code Block
languagejson
query($input: FoodSearchInput!){
    foods{
        search(input: $input)
        {
            foodSearchResults{
                id
                name
                modified
                created
                versionName
                foodType
                product
                supplier
                isApproved
                versionHistoryId
            }
            totalCount
            pageInfo{
                cursor
                hasNextPage
                startCursor
                endCursor
            }
        }
    }
}

GraphQL Variables

Code Block
languagejson
{
    "input":{
        "searchText":"recipe",
        "foodTypes":["Ingredient", "Recipe"],
        "itemSourceFilter":"All",
        "versionFilter":"Latest"
    }
}
Expand
titleResponse
Code Block
languagejson
"data": {
        "foods": {
            "search": {
                "foodSearchResults": [
                    ...
                    {
                        "id": "423f0ddd-14b2-4114-8323-7f8ccc11ddac",
                        "name": "granola, prepared from recipe",
                        "modified": "2023-03-27T16:57:27.4906008+00:00",
                        "created": "2023-03-27T16:57:27.4838005+00:00",
                        "versionName": "V1",
                        "foodType": "Ingredient",
                        "product": "USDA",
                        "supplier": "USDA SR-Legacy",
                        "isApproved": true,
                        "versionHistoryId": "4b7f32ab-3bae-469d-bce8-2dfd28b726d0"
                    },
                    {
                        "id": "21b52b33-2fde-498e-9a44-5023f98260b4",
                        "name": "taffy, prepared from recipe",
                        "modified": "2023-03-27T18:53:40.3575528+00:00",
                        "created": "2023-03-27T18:53:40.3504859+00:00",
                        "versionName": "V1",
                        "foodType": "Ingredient",
                        "product": "Canadian Nutrient File",
                        "supplier": "Health Canada (Canadian Nutrient File)",
                        "isApproved": true,
                        "versionHistoryId": "fb308722-32c1-45c8-8666-42ba8e0a329c"
                    },
                    {
                        "id": "a7eaee32-6ecd-4ece-90d0-48300d9d4439",
                        "name": "divinity, prepared from recipe",
                        "modified": "2023-03-27T17:44:05.6121672+00:00",
                        "created": "2023-03-27T17:44:05.6036143+00:00",
                        "versionName": "V1",
                        "foodType": "Ingredient",
                        "product": "USDA",
                        "supplier": "USDA SR-Legacy",
                        "isApproved": true,
                        "versionHistoryId": "db00f784-1a0d-4b14-a4cd-dd53b8487475"
                    },
                    ...
                ],
                "totalCount": 1407,
                "pageInfo": {
                    "cursor": 10,
                    "hasNextPage": true,
                    "startCursor": 0,
                    "endCursor": 1407
                }
            }
        }
    }
}

Getting an Analysis

Analyzing your foods is a core use case for Genesis. There are 2 types of analyses you can request: Gross and Net.

...

Expand
titleRequest

Query

Code Block
languagegraphql
query($input : GetAnalysisInput!){
    analysis{
        getAnalysis(input: $input){
            analysis{
                analysisType
                nutrientInfos{
                    nutrient{
                        id
                        name
                    }
                    value
                }
                amountAnalyzed{
                    quantity{
                        value
                    }
                    unit{
                        name
                    }
                }
                weight{
                   quantity{
                        value
                    }
                    unit{
                        name
                    } 
                }
            }
        }
    } 
}

GraphQL Variables

Code Block
{
    "input":{
        "foodId":"855f573f-9977-4625-8241-c6a3ee847b84",
        "analysisInput":{
            "analysisType": "Net",
            "amount":{
                "quantity":"100",
                "unitId":"a7df0af5-0008-0000-7484-751e8eaf05c6"
            }
        }
    }
}
Expand
titleResponse
Code Block
languagejson
"data": {
        "analysis": {
            "getAnalysis": {
                "analysis": {
                    "analysisType": "Net",
                    "nutrientInfos": [
                        {
                            "nutrient": {
                                "id": "84a8709a-0000-0000-ebf9-90cea7d9d44f",
                                "name": "Calories"
                            },
                            "value": 258
                        },
                        {
                            "nutrient": {
                                "id": "84a8709a-0001-0000-ebf9-90cea7d9d44f",
                                "name": "Protein"
                            },
                            "value": 5.9
                        },
                        {
                   search(input: $input)        "nutrient": {
            foodSearchResults{                 id   "id": "84a8709a-0002-0000-ebf9-90cea7d9d44f",
            name                 modified   "name": "Carbohydrates"
            created                },
versionName                 foodType           "value": 57.8
    product                 supplier   },              isApproved          
      versionHistoryId             }     {
       totalCount             pageInfo{        "nutrient": {
       cursor                 hasNextPage        "id": "84a8709a-00cf-0000-ebf9-90cea7d9d44f",
       startCursor                 endCursor        "name": "Salt"
   }         }     } }

GraphQL Variables

Code Block
languagejson
{     "input":{     },
   "searchText":"recipe",         "foodTypes":["Ingredient", "Recipe"],         "itemSourceFilter":"All",      "value": 1.8725
 "versionFilter":"Latest"     } }
Expand
titleResponse
Code Block
languagejson
"data": {         "foods": {      },
      "search": {                 "foodSearchResults": [...
                    ],
...                    "amountAnalyzed": {
                        "idquantity": "423f0ddd-14b2-4114-8323-7f8ccc11ddac",{
                            "namevalue": "granola, prepared from recipe",100"
                        "modified": "2023-03-27T16:57:27.4906008+00:00"},
                        "createdunit": "2023-03-27T16:57:27.4838005+00:00", {
                            "versionNamename": "V1Gram",
                        "foodType": "Ingredient",}
                         "product": "USDA",
   },
                    "supplierweight": "USDA SR-Legacy",{
                        "isApprovedquantity": true, {
                            "versionHistoryIdvalue": "4b7f32ab-3bae-469d-bce8-2dfd28b726d0100"
                        },
                     {   "unit": {
                     "id": "21b52b33-2fde-498e-9a44-5023f98260b4",      "name": "Gram"
                 "name": "taffy, prepared from recipe",   }
                    }
"modified": "2023-03-27T18:53:40.3575528+00:00",                }
            "created": "2023-03-27T18:53:40.3504859+00:00",}
        }
    }
}

Querying Standard Entities

There are several examples of standard entities in the data. These include units of measure, products, suppliers, etc.

...

Expand
titleRequest

Query

Code Block
languagegraphql
query{
    units{
     "versionName": "V1",  getStandard
        {
            units{
"foodType": "Ingredient",               id
         "product": "Canadian Nutrient File",    name
                dimension
   "supplier": "Health Canada (Canadian Nutrient File)",    }
        }
    } 
}
Expand
titleResponse
Code Block
languagejson
{
    "isApproveddata": true,{
        "units": {
              "versionHistoryIdgetStandard": "fb308722-32c1-45c8-8666-42ba8e0a329c"{
                    },"units": [
                    {
                        "id": "a7eaee32f14819b2-6ecde1b6-4ece4f8b-90d09b85-48300d9d443908d43583ec09",
                        "name": "divinity, prepared from recipeIndividual Carton",
                        "modifieddimension": "2023-03-27T17:44:05.6121672+00:00",Discrete"
                    },
                   "created": "2023-03-27T17:44:05.6036143+00:00", {
                        "id"versionName": "V1: "e92dc923-6da8-4fe1-9380-6564201d70c2",
                        "foodTypename": "IngredientKit",
                        "productdimension": "USDADiscrete",
                        "supplier": "USDA SR-Legacy"},
                        "isApproved": true,{
                        "versionHistoryIdid": "db00f784a7df0af5-1a0d0001-4b140000-a4cd7484-dd53b8487475751e8eaf05c6",
                    },    "name": "Teaspoon",
                  ...      "dimension": "Volume"
         ],           },
     "totalCount": 1407,              {
  "pageInfo": {                     "cursorid": 10"a7df0af5-0002-0000-7484-751e8eaf05c6",
                        "hasNextPagename": true,"Tablespoon",
                        "startCursordimension": 0,"Volume"
                    },
  "endCursor": 1407                 }{
            }         }   "id":  }
}

Getting an Analysis

Expand
titleRequest

Query

Code Block
languagegraphql
query($input : GetAnalysisInput!){"a7df0af5-0003-0000-7484-751e8eaf05c6",
               analysis{         getAnalysis(input: $input){"name": "Cup",
            analysis{            "dimension": "Volume"
   analysisType                 nutrientInfos{},
                    nutrient{...            
            id    ]
            }
       name }
    }
}

Creating an Ingredient

...

Expand
titleRequest

Mutation

Code Block
languagegraphql
mutation($input : CreateFoodInput!){
     foods{
     }   create(input:$input)
        {
        value    food{
            }    id
            amountAnalyzed{    name
                quantitydefiningAmount{
                    quantity{
   value                     }value
                    unit{}
                    unit{
   name                     }id
                }        name
        weight{            }
       quantity{         }
               value conversions{
                   } from{
                   unit{     quantity{
                   name         value
           }             }
    }             }       unit{
 }     }  }

GraphQL Variables

Code Block
{     "input":{         "foodId":"855f573f-9977-4625-8241-c6a3ee847b84",         id
"analysisInput":{             "analysisType": "Net",             "amount":{ name
               "quantity":"100",         }
       "unitId":"a7df0af5-0008-0000-7484-751e8eaf05c6"             }
             }     } }
Expand
titleResponse
Code Block
languagejson
"data": { to{
                   "analysis": {    quantity{
        "getAnalysis": {                 "analysis": { value
                   "analysisType": "Net",    }
                "nutrientInfos": [       unit{
                 {           id
                 "nutrient": {          name
                      "id": "84a8709a-0000-0000-ebf9-90cea7d9d44f",
 }
                    }
          "name": "Calories"     }
            }
        }
 },   }
}

GraphQL Variables

Code Block
languagejson
{
    "input":{
        "name":"Test Ingredient Name",
        "valuefoodType":"Ingredient"
258    }
}
Expand
titleResponse
Code Block
languagejson
{
    "data": {
        "foods": {
   },         "create": {
              {       "food": {
                     "nutrientid": {"bd975a4b-5bc0-4e8a-885d-a9c1f586125b",
                    "name": "Test Ingredient Name",
        "id": "84a8709a-0001-0000-ebf9-90cea7d9d44f",            "definingAmount": {
                        "namequantity": "Protein"{
                            },"value": "100"
                        },
    "value": 5.9                   "unit": {
    },                         {"id": "a7df0af5-0008-0000-7484-751e8eaf05c6",
                            "nutrientname": {"Gram"
                          }
     "id": "84a8709a-0002-0000-ebf9-90cea7d9d44f",                 },
               "name": "Carbohydrates"    "conversions": [
                        },{
                            "valuefrom": 57.8{
                         },       "quantity": {
                                    "value": "1"
  {                             "nutrient": { },
                                "idunit": "84a8709a-00cf-0000-ebf9-90cea7d9d44f", {
                                    "nameid": "Salt"
          a7df0af5-0063-0000-7484-751e8eaf05c6",
                 },                   "name": "Batch Weight"
       "value": 1.8725                         },
                        ...    },
                ],            "to": {
       "amountAnalyzed": {                         "quantity": {
                                    "value": "100"
                        },        },
                "unit": {               "unit": {
            "name": "Gram"                       "id":  }"a7df0af5-0008-0000-7484-751e8eaf05c6",
                     },               "name": "Gram"
    "weight": {                         "quantity": { }
                           "value": "100" }
                        },
                        "unit": {
                            "namefrom": "Gram"{
                        }        "quantity": {
           }                 }        "value": "100"
   }         }     } }

Querying Standard Entities

There are several examples of standard entities in the data. These include units of measure, products, suppliers, etc.

Expand
titleRequest

Query

Code Block
query{     units{         getStandard},
        {             units{           "unit": {
    id                 name               "id":  dimension"a7df0af5-0008-0000-7484-751e8eaf05c6",
               }         }     }  }
Expand
Code Block
languagejson
{     "dataname": { "Gram"
                              "units": { }
           "getStandard": {                },
"units": [                     {      "to": {
                 "id": "f14819b2-e1b6-4f8b-9b85-08d43583ec09",              "quantity": {
         "name": "Individual Carton",                         "dimensionvalue": "Discrete1"
                    },             },
       {                         "idunit": "e92dc923-6da8-4fe1-9380-6564201d70c2",{
                                    "nameid": "Kit"a7df0af5-0064-0000-7484-751e8eaf05c6",
                        "dimension": "Discrete"           "name": "Batch Yield"
       },                     {    }
                    "id": "a7df0af5-0001-0000-7484-751e8eaf05c6",        }
                "name": "Teaspoon",         }
               "dimension": "Volume"    ]
                },
            }
       { }
    }
}

Creating a Recipe

...

Expand
titleRequest

Mutation

Code Block
mutation($input :  CreateFoodInput!){
    foods{
         "id": "a7df0af5-0002-0000-7484-751e8eaf05c6",create(input:$input)
        {
            food{
   "name": "Tablespoon",             id
           "dimension": "Volume"    name
                },
            }
       { }
}

GraphQL Variables

Code Block
{
    "input":{
        "name":"Test Recipe  Name",
     "id": "a7df0af5-0003-0000-7484-751e8eaf05c6",    "foodType":"Recipe"
    }
}
Expand
titleResponse
Code Block
{
    "data": {
        "namefoods": "Cup",{
            "create": {
          "dimension": "Volume"     "food": {
              },      "id": "0f33eb79-7ba1-48eb-acd6-1f8c22858cea",
             ...       "name": "Test Recipe Name"
                  ]}
            }
        }
    }
}

Creating an Ingredient

...