# Setting up instant transaction sync for Monzo and YNAB These instructions cover setting up [`fintech-to-ynab`](https://github.com/syncforynab/fintech-to-ynab) in a Docker container to enable to instant transaction sync from Monzo to YNAB. In addition to active Monzo and YNAB accounts, these steps assume you already have the following in place: * A domain * An always-on computer or server with Docker installed * Nginx or another web server/reverse proxy solution, plus a basic understanding of setting up new proxy configurations Please see the Additional Resources section for more information on the above pre-requisites. ## Retrieve the environment variables 1. In YNAB, set up a new (unlinked) checking account that will be used to house your Monzo transactions. Name it whatever you'd like, for example, "Monzo." 2. You will need to retrieve both the YNAB budget ID (the identifier for the primary budget you use in YNAB) and the YNAB "account ID" for the unlinked account you just created. In the YNAB web app, navigate to the new unlinked account and copy the respective portions of the URL in the address bar, which should look something like this: `https://app.youneedabudget.com/[budget_id]/accounts/[account_id]`. Write down both the budget ID and the account ID - you'll need them later to pass to the container. 3. Retrieve a [YNAB access code](https://api.youneedabudget.com/#authentication). Again, write it down. ## Set up your domain, container, and reverse proxy 1. In your domain provider's settings, set up a new CNAME record for the subdomain you want to use - for example, `budget.yourdomain.com`. 2. On your Docker server, create a new container: `docker pull ghcr.io/syncforynab/fintech-to-ynab:latest` 3. Run the container (adapt these commands accordingly based on your platform, i.e. `docker-compose`, Unraid, Synology, etc.): - ### Docker run 1. Copy & paste the code below into a terminal 2. Replace the 'xxxx's and the APP_HOSTNAME field with your information ``` docker run -d \ -p 3000:3000 \ -e YNAB_ACCESS_TOKEN="xxxx" \ -e YNAB_BUDGET_ID="xxxx" \ -e YNAB_MONZO_ACCOUNT_ID="xxxx" \ -e APP_HOSTNAME="budget.yourdomain.com" \ ghcr.io/syncforynab/fintech-to-ynab:latest ``` - ### Docker Compose 1. Copy & paste the code below into a text editor 2. Replace the 'xxxx's and the APP_HOSTNAME field with your information and setup the section labeled "swag" in accordance with the docs [here](https://github.com/linuxserver/docker-swag#parameters) to best meet your needs. *Tip: make sure to update the "subdomains" value to include `budget` or whatever you've set as your CNAME, in addition to `www`.* 3. Save to file named docker-compose.yml 4. Navigate to the directory you saved the file to in a terminal 5. Run `docker compose up -d` ``` version: "2.1" services: fintech-to-ynab: image: ghcr.io/syncforynab/fintech-to-ynab:latest container_name: Monzo-To-YNAB environment: - YNAB_MONZO_ACCOUNT_ID="xxxx" - YNAB_BUDGET_ID="xxxx" - YNAB_ACCESS_TOKEN="xxxx" - APP_HOSTNAME="budget.yourdomain.com" ports: - 3000:3000 restart: unless-stopped swag: image: lscr.io/linuxserver/swag container_name: swag cap_add: - NET_ADMIN environment: - PUID=1000 - PGID=1000 - TZ=Europe/London - URL=yourdomain.url - SUBDOMAINS=www, - VALIDATION=http - CERTPROVIDER= #optional - DNSPLUGIN=cloudflare #optional - DUCKDNSTOKEN=<token> #optional - EMAIL=<e-mail> #optional - ONLY_SUBDOMAINS=false #optional - EXTRA_DOMAINS=<extradomains> #optional - STAGING=false #optional volumes: - </path/to/appdata/config>:/config ports: - 443:443 - 80:80 #optional restart: unless-stopped ``` 4. In your reverse proxy, create a new proxy configuration for the subdomain you created earlier. Ensure it forwards to the host IP and port you set up in the container configuration (here, `3000`). For example, in the SWAG `proxy-confs` directory, create a file named `budget.subdomain.conf` or similar, replacing the `server_name` and `proxy_pass` values to fit your setup: ``` # make sure that your dns has a cname set for fintech-to-ynab server { listen 443 ssl; listen [::]:443 ssl; server_name budget.yourdomain.com; include /config/nginx/ssl.conf; client_max_body_size 0; location / { # enable the next two lines for http auth #auth_basic "Restricted"; #auth_basic_user_file /config/nginx/.htpasswd; # enable the next two lines for ldap auth #auth_request /auth; #error_page 401 =200 /ldaplogin; # enable for Authelia #include /config/nginx/authelia-location.conf; include /config/nginx/proxy.conf; include /config/nginx/resolver.conf; proxy_pass http://[YOUR HOST IP]:3000; } } ``` 5. Save the file and restart the `SWAG` Docker or your alternative reverse proxy to incorporate the changes. ## Set up Monzo webhooks 1. Log in to [Monzo Developer Portal](https://developers.monzo.com) with your Monzo email. It will email you a login link and ask you to verify API access in the mobile app. 2. Click "register webhook" on the left. 3. Paste the URL of your app - the subdomain we created earlier - into the "URL" value of Request Body, and make sure to append `/monzo` to it. For example: `https://budget.yourdomain.com/monzo`. You will get errors if you don't do this! 4. The `account_id` variable should be the "Account ID" listed at the top of the page (NOT your YNAB account ID that you wrote down earlier). Finally, test it out! Make a transfer to or from Monzo or between Pots and check the YNAB account. Transactions should sync within several seconds (if it doesn't, check the `fintech-to-ynab` Docker logs as a first step towards troubleshooting) ## Additional resources 1. Docker - https://docs.docker.com/engine/install/ 2. Nginx web server within Docker - https://linuxiac.com/nginx-docker/ 3. Nginx web server without Docker - https://nginx.org/en/docs/install.html 4. LinuxServer's SWAG container (Nginx web server + Let's Encrypt SSL certificates for your domain) - https://docs.linuxserver.io/images/docker-swag