The self-hosted recipe manager Mealie startet to support sending a recipe to a Bring shopping list with this PR. However, this requires the Mealie instance to be publicly available (from the internet). Since many users want their self-hosted services to not be available from the internet, I chose to create this integration.
This project provides the source code and a container image for a simple webserver which listens for requests by the Mealie instance and adds the ingredients of a recipe to a specified Bring shopping list.
- The
Mealie instance
sends aGET
request to the recipe toAPI of bring
(See Bring API docs).- The link looks like
this
https://api.getbring.com/rest/bringrecipes/deeplink?url=<mealieinstance>g/home/r/<recipe>&source=web
.
- The link looks like
this
Bring
then does aGET
request to theMealie instance
and pulls the ingredients.- In order for this to work the
Mealie instance
has to be reachable from the public internet. - This opens an attack vector as anyone can access the
Mealie instance
.
- In order for this to work the
- The
Mealie instance
sends aPOST
request to thiswebserver
with the ingredients in its body. - The
webserver
extracts the ingredients from the request and adds them directly to a list of the users choice via theBring API
.
No matter which deployment option you chose you must setup some environment variables:
Variable name | Description | Required | Default | Example |
---|---|---|---|---|
BRING_USERNAME |
The email address of your bring account | Yes | - | [email protected] |
BRING_PASSWORD |
The password of your bring account | Yes | - | my super secret password |
BRING_LIST_NAME |
The exact name of the list you want to add the ingredients to, supports special characters | Yes | - | My shopping list with spaces |
IGNORED_INGREDIENTS |
Ingredients that are never added to the shopping list (things you always have at home), separated by a , , case insensitive, WARNING: This only works for recipes with enabled ingredient amounts in the recipe settings! |
No | - (all ingredients will be added) | Salt,Pepper,Frying oil |
LOG_LEVEL |
The loglevel the application logs at | No | INFO |
DEBUG |
HTTP_HOST |
The address the application tries to attach to, leave this empty to listen on all interfaces, leave this empty if you are using Docker | No | 0.0.0.0 |
192.168.1.5 |
HTTP_PORT |
The port the application listens on, change this if needed if you run the application locally, leave this empty if you are using Docker | No | 8742 |
1234 |
Ensure to quote your environment variables. Without quotes your password might not be read properly if it contains symbols such as <
, &
or ;
.
You can run this app in three simple ways. I prefer the third option. Depending on the deployment option you chose
you can ignore some environment variables (e.g. HTTP_HOST
and HTTP_PORT
).
- Copy the contents
./assets/env.example
to./.env
and adjust the environment variables to your needs. - (Optional) Create and activate a virtual environment with
python -m venv .venv; source .venv/bin/activate
. - Install the requirements with
pip install -r ./assets/requirements.txt
. - Run
python source/main.py
.
- Run
docker run mealie-api
and pass in your environment variables with-e
.- You can (not must) specify a different port than the default (
8742
) with-p 1234:8742
. - Example:
docker run \ -e BRING_USERNAME="[email protected]" \ -e BRING_PASSWORD="my super secret password" \ -e BRING_LIST_NAME="My shopping list with spaces" \ -p 1234:8742 \ ghcr.io/felixschndr/mealie-bring-api:latest
- You can (not must) specify a different port than the default (
- Add this container to your existing docker-compose next to your Mealie instance or create a new docker-compose and adjust the environment variables to your needs. Take a look at the example docker-compose.
- Run
docker-compose up
.
After deploying the container, there is one simple step you have to do in Mealie: You have to set up the link between Mealie and this project.
-
Head over to
http(s)://<your-mealie-instance>/group/data/recipe-actions
(e.g.,http://localhost:1234/group/data/recipe-actions
) while being logged in as an administrator. -
Click on
Create
to create a newaction
. -
Give it any title (e.g.
Bring
orAdd ingredients to Bring
). This will be visible for the users. -
For the
URL
input the address where this project is running on followed by a/
(e.g.http://localhost:8742/
orhttps://mealie-bring-api.yourlocaldomain.com/
if you are using a reverse proxy) -
Change the
Type
toPOST
-
Save
-
Try it out 🎉
-
Head over to a recipe of your choice.
-
Click on the three little dots.
-
Click on
Recipe Actions
-
Chose your new action (e.g.
Bring
) -
That's it!
- You should now see the ingredients in your list
- You should see some output in the logfile
mealie_bring_api | [2024-05-18 13:38:41,090] [LoggerMixin] [INFO] [Received recipe "Apple crumble" from "https://mealie-bring-api.yourlocaldomain.com"] mealie_bring_api | [2024-05-18 13:38:45,373] [LoggerMixin] [INFO] [Added all ingredients to Bring]
You can check whether the webserver is still alive by sending a GET
request to /status
and check if you get a 200
status code:
$ curl -I https://mealie-bring-api.yourlocaldomain.com/status
HTTP/2 200
server: openresty
date: Mon, 20 May 2024 12:27:56 GMT
content-type: text/html; charset=utf-8
content-length: 2
strict-transport-security: max-age=63072000; preload
or
$ curl -s -o /dev/null -w "%{http_code}" https://mealie-bring-api.yourlocaldomain.com/status
200