Genesis Foods - Exporting to CSV

Overview

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

Simply follow the instructions below (specifically for MacOS or Windows) to demonstrate how to export recipe information to CSV format.

Download the Files

You will need to download two files - the script that runs the export and a configuration file for the options. These can be downloaded from the Genesis Foods API Example repository (GitHub - esha/genesis-foods-api-examples: Genesis Foods GraphQL API Playground ) using the raw download option on the following pages.

export_to_csv.py

Download export_to_csv.py here

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

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.

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

  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 Files

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

output_csv

The name of the CSV file you’d like to save the results to. Defaults to genesis_recipes.csv

limit

Limits the number of recipes that will be output to a CSV file. Set this to a lower number for testing purposes. If not present, the script will default to 10000.

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.

 

 

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.

 

 

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

 

 

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.

 

 

We’re now ready to run the export script!

Running the Export Script

1

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

cd ~/Downloads

 

 

2

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

 

 

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.

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.

3

Now we need to download a plugin - issue the command

pip install requests

To download the plugin we need to run the script.

We’re now ready to run the export script!

Running the Export Script

1

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

cd Downloads

 

 

2

Run the command python export_to_csv.py

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.