Last active
July 21, 2026 01:05
-
-
Save matthewbauer/08a58a61286a8a2eab89d5f7a1a4a8a0 to your computer and use it in GitHub Desktop.
Mercury Hledger Rules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Hledger rules for Mercury (mercury.com) transactions. | |
| # Requires the official `mercury` CLI tool[1] as well as jq. | |
| # | |
| # Authenticate once with: | |
| # | |
| # mercury login | |
| # | |
| # Then convert to journal format: | |
| # | |
| # hledger -f mercury.rules print | |
| # | |
| # or import just the new transactions into your main journal: | |
| # | |
| # hledger import mercury.rules | |
| # | |
| # [1]: https://github.com/MercuryTechnologies/mercury-cli | |
| source | mercury transactions list --format json | jq -r '[ (.postedAt // .createdAt)[:10], .id, .amount, .status, .kind, .accountId, (.trackingNumber // ""), (.counterpartyName // ""), (.counterpartyId // ""), (.bankDescription // ""), (.note // ""), (.categoryData.name // .mercuryCategory // ""), (.merchant.category // .mercuryCategory // "") ] | @csv' | |
| fields date, id, amount, txnstatus, kind, accountId, trackingNumber, counterpartyName, counterpartyId, bankDescription, note, category, merchantCategory | |
| currency $ | |
| account1 assets:bank:mercury:%accountId | |
| description %counterpartyName | |
| if %bankDescription [^ ] | |
| description %counterpartyName | %bankDescription | |
| comment kind:%kind, mercury_id:%id | |
| if %note . | |
| comment kind:%kind, mercury_id:%id, note:%note | |
| if %txnstatus (failed|cancelled) | |
| skip | |
| if %trackingNumber . | |
| code %trackingNumber | |
| if %txnstatus pending | |
| status ! | |
| if %merchantCategory . | |
| account2 expenses:%merchantCategory | |
| if %merchantCategory other | |
| account2 expenses:unknown | |
| if %category Interest Earned | |
| account2 income:interest | |
| if %kind (internalTransfer|treasuryTransfer) | |
| account2 assets:bank:mercury:clearing:%counterpartyId |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment