Genesis Foods - Importing from a CSV File

Genesis Foods - Importing from a CSV File

Overview

This page outlines the steps necessary to interact with the Genesis Foods API to import a file from CSV format into Genesis Foods. It utilizes Python, a common computer programming language, to interface with the Genesis Foods API, but users don’t need to know the details to work with it.

Follow the instructions below (specifically for macOS or Windows) to demonstrate how to import recipe information from CSV format.

Download the Files

You will need to download three files - the script that runs the import, a CSV template, and a configuration file for the options. These can be downloaded from the Genesis Foods API Example repository (https://github.com/esha/genesis-foods-api-examples ) using the raw download option on the following pages.

import_from_csv.py

Download import_from_csv.py here

Screen Shot 2024-11-20 at 11.37.14 AM.png

logging_config.py

Download logging_config.py here

config.ini

Download config.ini here

On Windows, you may need to force a download as the browser will potentially warn about downloading this file.

ingredient_import.csv

Download ingredient_import.csv here

 

constants.py

Download constants.py here

 

Take note of what directory you’ve downloaded those files to - that will be important in subsequent steps.

Get Your API Key

Follow the steps listed here to download the API Key for your account. For full reference, check out https://esharesearch.atlassian.net/wiki/spaces/GGA/pages/3293282331/Getting+Started+with+the+Trustwell+Genesis+Foods+GraphQL+API#Obtaining-your-API-Key

  • 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.

  1. Log into the Genesis Foods application.

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

  3. Select Profile.

    image-20241010-225201.png
  4. Select API Tokens along the top.

    image-20241010-225301.png
  5. Click Create API Token.

  6. Enter a Label.

  7. Click Create Token.

  8. Once created, we recommend using the Copy button to copy the string to the clipboard. We will need to save this API Key in the configuration file in the next step.

Update the Configuration File

The configuration file config.ini contains settings that will be used in the export process. The list of key settings necessary for this script is found below. Use your favorite text editor to open up the file and make changes to the 3 keys below:

Setting

Value

Setting

Value

endpoint

For production use cases, use https://api.trustwell.com/genesis

For working against the preview environment, use https://api-preview.trustwell.com/genesis

api_key

The API key you obtained from Genesis Foods in the section above.

input_csv

The name of the CSV file you’d like to import from. Defaults to ingredient_import.csv

CSV Template Columns / Attributes

The default CSV template includes several fields, most of which are optional and can be left blank if not needed.

Column

Notes

Column

Notes

Name

Required. The desired name of the ingredient.

Supplier

Optional. The name of the supplier of the ingredient. The supplier will be created if it does not already exist in Genesis Foods.

Alias

Optional. One or more comma-separated aliases for population are included in the Alias section of Genesis Foods.

Status

Optional. Defaults to Draft if blank.

Draft ingredients will be imported as Draft ingredients - making them suitable for review before marking them for approval.

Approved ingredients will take a draft ingredient and

  • Verify the allergens are correct

  • Approve the ingredient

Approved ingredients can only be archived and cannot be deleted! For testing purposes, it is strongly recommended to import ingredients as Draft for review before proceeding!

Weight and Unit

Optional. The weight and units. Defaults to 100 grams.

Authority

Optional. The name of the regulatory authority to use for assigning allergens. Only used for allergens. Valid values are United States, US, Canada, CA, Mexico, MX, AUS, Australia, NZ, EU, European Union. Defaults to US if not present.

Contains Allergens

Optional. A comma-separated list of allergens that belong in the Contains statement.

Example: Sesame, Peanut

May Contain Allergens

Optional. A comma-separated list of allergens that belong in the May Contain statement.

Example: Sesame, Peanut

Nutritional fields (Calories, Protein, etc)

Optional. Each nutritional field can optionally be set to set the value (in standard units) for the nutrient.

What if I am exporting a CSV file from some other system? Do I need to update my column headers in that file?

There are multiple paths available. Let’s say, for example, the exported CSV has sugars_added as a column header.

  1. Using the exported file as your import file, update the exported CSV column headers so that the header directly aligns with the names listed in the ingredient_import.csv template.

    1. Example: You would update the sugars_added column header in the exported file to Added Sugar, which is the default nutrient name in Genesis Foods.

  2. Using the exported file as your import file, update the data mapping in constants.py to align with your exported CSV file’s headers. This will tell the script to use a different header for the lookup.

    1. Example: Within the constants.py file, find the row for Added Sugar and change the key to added_sugars

      1. Old: "Added Sugar": "84a8709a-0094-0000-ebf9-90cea7d9d44f",

      2. New: "sugars_added": "84a8709a-0094-0000-ebf9-90cea7d9d44f",

  3. Copy the values from your exported file into the import template in the appropriate column (you will then use the import template as your import file).

MacOS Instructions

One-Time System Setup

Python is already installed by default on MacOS, so we just need to install a few plugins to help the script work.

You only need to do this once, regardless of how often you plan to use the export process.

1

Open the Terminal application. You can do this from your dock or through Spotlight search by clicking on command+spacebar.

 

Screen Shot 2024-11-19 at 5.21.13 PM.png

 

2

Let’s next check the command to launch Python, as it may vary depending on your OS version. Issue the commands

which python

which python3

to see which Python executable we have installed. In the example on the right, our Python executable is python3 as indicated by the response.

 

Screen Shot 2024-11-19 at 5.26.02 PM.png

 

3

Similarly, we’ll need to check the path for pip - which is the package installer for Python. Issue the commands

which pip

which pip3

to see which pip executable is available. In the example on the right, both pip and pip3 are available (they are likely the same, but that’s an advanced topic).

 

Screen Shot 2024-11-19 at 5.27.42 PM.png

 

4

Now we need to download a plugin - issue the command

pip install requests or pip3 install requests (depending on the executable that was available in Step 3) to install the requests package.

 

Screen Shot 2024-11-19 at 5.37.41 PM.png

 

We’re now ready to run the export script!

Proceed carefully! This import job will create records in your Genesis Foods database each time it is executed. Subsequent runs of the same records will create duplicate ingredients (not update existing).
Consider the following recommendations:

  1. Test will a small amount of data (i.e. 5 rows) to ensure results are as expected.

  2. Test using a Status of Draft to allow for manual deletion of the records after import.

Running the Import Script

1

Change to the directory you downloaded the file. For macOS, this will most likely be the Downloads directory.

cd ~/Downloads

 

Screen Shot 2024-11-20 at 1.13.35 PM.png

 

2

Run the command import_from_csv.py (depending on whether your executable was python or python3).

 

Screen Shot 2024-11-20 at 4.19.48 PM.png

 

If you receive an error that looks like ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.0.2r  26 Feb 2019' then you will need to issue two additional commands to continue the setup process (just once)

pip uninstall urllib3

pip install 'urllib3<2.0'

Once this is complete, the script should be able to run to completion.

You will see the script run, and the CSV file will be exported based on the configuration option you set in the output_csv variable.

Microsoft Windows Instructions

One-Time System Setup

For Windows, we’ll need to first install Python.

1

Go to the Microsoft Store and search for Python. There may be multiple versions of Python available; you can select the latest one.

Screen Shot 2024-11-20 at 2.53.52 PM.png
A Microsoft Store search for Python
Screen Shot 2024-11-20 at 2.54.08 PM.png
Click “Get” to download to your system.
2

Next, let’s open up the PowerShell application where we’ll be doing the work. Search Powershell in the search menu to find and open the application.

Screen Shot 2024-11-20 at 3.04.10 PM.png
The Windows PowerShell application
Screen Shot 2024-11-20 at 3.04.19 PM.png
An open PowerShell Application
3

Now we need to download a plugin - issue the command

pip install requests

To download the plugin we need to run the script.

Screen Shot 2024-11-20 at 3.08.58 PM.png

We’re now ready to run the import script!

Proceed carefully! This import job will create records in your Genesis Foods database each time it is executed. Subsequent runs of the same records will create duplicate ingredients (not update existing).
Consider the following recommendations:

  1. Test will a small amount of data (i.e. 5 rows) to ensure results are as expected.

  2. Test using a Status of Draft to allow for manual deletion of the records after import.

Running the Import Script

1

Change to the directory you downloaded the import_from_csv.py file above. For Windows, this will most likely be the Downloads directory.

cd Downloads

 

Screen Shot 2024-11-20 at 3.11.00 PM.png

 

2

Run the command python import_from_csv.py

Screen Shot 2024-11-20 at 3.11.55 PM.png

You will see the script run, and the CSV file will be imported to Genesis Foods as separate ingredients.

Clicking links may navigate you away from the Trustwell site.