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:
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="myuser@myemailprovider.com" \ -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