wesselt/bunq2ynab

Syncing transactions between two bankaccounts fails

arnemauer opened this issue · 7 comments

When i transfer money between my own bunq accounts, syncing these transactions to Ynab fails.

File "/var/task/lib/ynab.py", line 56, in call

raise Exception("{0} (details: {1})".format(
Exception: bad_request (details: payee must be formatted as a uuid (universally unique identifier) (index: 0))

This is the transaction that fails:

{
"transactions": [
{
"import_id": "YNAB:-1000:2024-06-27:1",
"account_id": "f2064ef4-fd30-4ba1-81b9-ee95378fed55",
"date": "2024-06-27",
"amount": -1000,
"memo": "Test2",
"cleared": "cleared",
"payment": {
"amount": "-1.00",
"date": "2024-06-27",
"type": "BUNQ",
"sub_type": "PAYMENT",
"iban": "NLxxBUNQxxxxxxxxxx",
"payee": "xxxxxxx  xxxxxxxx",
"description": "Test2"
},
"new": true,
"payee_id": "Gezamenlijke betaalrekening"
},
{
"import_id": "YNAB:1000:2024-06-27:1",
"account_id": "f2064ef4-fd30-4ba1-81b9-ee95378fed55",
"date": "2024-06-27",
"amount": 1000,
"memo": "Test",
"cleared": "cleared",
"payment": {
"amount": "1.00",
"date": "2024-06-27",
"type": "BUNQ",
"sub_type": "PAYMENT",
"iban": "NLxxBUNQxxxxxxxxxx",
"payee": "xxxxxxx  xxxxxxxx",
"description": "Test"
},
"new": true,
"payee_id": "Incassorekening"
}
]
}

Is it right that the payee_id is the name of the account? Or should it be the unique id of the account in Ynab?

The payee_id looks like the ID of a YNAB payee, like you would get from https://api.ynab.com/v1#/Payees/getPayees The error message you get from YNAB says it should always be a GUID.

For a payment between your own accounts bunq2ynab sets the account's "transfer_payee_id", so it shows in YNAB as a transfer instead of a payment. I wonder how that gets set to "Boodschappen"! What "transfer_payee_id" does the YNAB API return in reply to v1/budgets?include_accounts=true?

{
    "data": {
        "budgets": [
            {
                "id": "f26d6114-6920-42a1-96df-9165c69ccce3",
                "name": "My Budget",
                "last_modified_on": "2024-06-28T05:47:49Z",
                "first_month": "2018-01-01",
                "last_month": "2024-07-01",
                "date_format": {
                    "format": "DD-MM-YYYY"
                },
                "currency_format": {
                    "iso_code": "EUR",
                    "example_format": "123,456.78",
                    "decimal_digits": 2,
                    "decimal_separator": ",",
                    "symbol_first": true,
                    "group_separator": ".",
                    "currency_symbol": "",
                    "display_symbol": true
                },
                "accounts": [
                    {
                        "id": "0ee15160-e5b1-47f6-b0d9-dece8025aa85",
                        "name": "Oud - Gezamenlijke rekening",
                        "type": "checking",
                        "on_budget": true,
                        "closed": false,
                        "note": null,
                        "balance": 0,
                        "cleared_balance": 0,
                        "uncleared_balance": 0,
                        "transfer_payee_id": "01ea3d81-7d9d-4a35-a006-d56822ddb52c",
                        "direct_import_linked": false,
                        "direct_import_in_error": false,
                        "last_reconciled_at": null,
                        "debt_original_balance": null,
                        "debt_interest_rates": {},
                        "debt_minimum_payments": {},
                        "debt_escrow_amounts": {},
                        "deleted": false
                    },
                    {
                        "id": "6ac11c6e-256d-43de-9520-8e480f6e5e3e",
                        "name": "Spaarrekening xxx en xxx",
                        "type": "savings",
                        "on_budget": true,
                        "closed": false,
                        "note": null,
                        "balance": 0,
                        "cleared_balance": 0,
                        "uncleared_balance": 0,
                        "transfer_payee_id": "f5345621-460b-41b6-93fc-1e8c1a41789b",
                        "direct_import_linked": false,
                        "direct_import_in_error": false,
                        "last_reconciled_at": "2024-02-17T20:23:34Z",
                        "debt_original_balance": null,
                        "debt_interest_rates": {},
                        "debt_minimum_payments": {},
                        "debt_escrow_amounts": {},
                        "deleted": false
                    },
                    {
                        "id": "eedfa43b-b4b3-4d76-9238-99e9bbcd6c56",
                        "name": "Vakantiegeld",
                        "type": "savings",
                        "on_budget": true,
                        "closed": false,
                        "note": null,
                        "balance": 0,
                        "cleared_balance": 0,
                        "uncleared_balance": 0,
                        "transfer_payee_id": "c24f6c2f-f090-421f-886a-5dadf65701bb",
                        "direct_import_linked": false,
                        "direct_import_in_error": false,
                        "last_reconciled_at": "2024-03-07T18:53:21Z",
                        "debt_original_balance": null,
                        "debt_interest_rates": {},
                        "debt_minimum_payments": {},
                        "debt_escrow_amounts": {},
                        "deleted": false
                    },
                    {
                        "id": "04ce358d-2a1e-4fbe-843f-1a5d152f4ca7",
                        "name": "Spaarrekening",
                        "type": "savings",
                        "on_budget": true,
                        "closed": false,
                        "note": null,
                        "balance": 0,
                        "cleared_balance": 0,
                        "uncleared_balance": 0,
                        "transfer_payee_id": "f411a48f-ea95-46e8-b1af-caface29bb57",
                        "direct_import_linked": false,
                        "direct_import_in_error": false,
                        "last_reconciled_at": "2024-03-07T18:53:26Z",
                        "debt_original_balance": null,
                        "debt_interest_rates": {},
                        "debt_minimum_payments": {},
                        "debt_escrow_amounts": {},
                        "deleted": false
                    },
                    {
                        "id": "7befebe6-34fa-4bf9-95e4-1e81198ba753",
                        "name": "Oud - Incassorekening",
                        "type": "checking",
                        "on_budget": true,
                        "closed": false,
                        "note": null,
                        "balance": 0,
                        "cleared_balance": 0,
                        "uncleared_balance": 0,
                        "transfer_payee_id": "baad6317-5a91-49bf-826d-7ae93f02ce0c",
                        "direct_import_linked": false,
                        "direct_import_in_error": false,
                        "last_reconciled_at": "2024-03-07T18:53:36Z",
                        "debt_original_balance": null,
                        "debt_interest_rates": {},
                        "debt_minimum_payments": {},
                        "debt_escrow_amounts": {},
                        "deleted": false
                    },
                    {
                        "id": "1dcd1911-aaa6-44e0-9274-6a8221ff0f0d",
                        "name": "Gezamenlijke betaalrekening",
                        "type": "checking",
                        "on_budget": true,
                        "closed": false,
                        "note": null,
                        "balance": 38580,
                        "cleared_balance": 38580,
                        "uncleared_balance": 0,
                        "transfer_payee_id": "ff71b537-4070-47b1-a4c2-2475d778fc69",
                        "direct_import_linked": false,
                        "direct_import_in_error": false,
                        "last_reconciled_at": "2024-06-25T20:08:37Z",
                        "debt_original_balance": null,
                        "debt_interest_rates": {},
                        "debt_minimum_payments": {},
                        "debt_escrow_amounts": {},
                        "deleted": false
                    },
                    {
                        "id": "f2064ef4-fd30-4ba1-81b9-ee95378fed55",
                        "name": "Spaar gezamenlijk",
                        "type": "savings",
                        "on_budget": true,
                        "closed": false,
                        "note": null,
                        "balance": 1167810,
                        "cleared_balance": 1167810,
                        "uncleared_balance": 0,
                        "transfer_payee_id": "8fdc96ae-1a67-4b8b-a74c-521755b8bffb",
                        "direct_import_linked": false,
                        "direct_import_in_error": false,
                        "last_reconciled_at": "2024-06-25T20:08:46Z",
                        "debt_original_balance": null,
                        "debt_interest_rates": {},
                        "debt_minimum_payments": {},
                        "debt_escrow_amounts": {},
                        "deleted": false
                    },
                    {
                        "id": "af4d241d-7bf9-48d3-827f-12075891c73a",
                        "name": "Boodschappen",
                        "type": "checking",
                        "on_budget": true,
                        "closed": false,
                        "note": null,
                        "balance": 371420,
                        "cleared_balance": 371420,
                        "uncleared_balance": 0,
                        "transfer_payee_id": "7a6826b0-1095-426d-ac3b-82b898082499",
                        "direct_import_linked": false,
                        "direct_import_in_error": false,
                        "last_reconciled_at": "2024-06-25T20:08:28Z",
                        "debt_original_balance": null,
                        "debt_interest_rates": {},
                        "debt_minimum_payments": {},
                        "debt_escrow_amounts": {},
                        "deleted": false
                    },
                    {
                        "id": "c3ad6b6f-ac02-4e98-98e2-5c2e9542b5cd",
                        "name": "Incassorekening",
                        "type": "checking",
                        "on_budget": true,
                        "closed": false,
                        "note": null,
                        "balance": 5412960,
                        "cleared_balance": 5412960,
                        "uncleared_balance": 0,
                        "transfer_payee_id": "851ca3d7-9440-4275-83df-1b10aa04aa57",
                        "direct_import_linked": false,
                        "direct_import_in_error": false,
                        "last_reconciled_at": "2024-06-25T20:06:32Z",
                        "debt_original_balance": null,
                        "debt_interest_rates": {},
                        "debt_minimum_payments": {},
                        "debt_escrow_amounts": {},
                        "deleted": false
                    }
                ]
            }
        ],
        "default_budget": null
    }
}

Thanks for posting the accounts, that looks as expected. All the "transfer_payee_id" fields are GUIDS. So I wonder how "Boodschappen" got into the payee_id field. If I search for "payee_id" in the code, it is only set from the "transfer_payee_id": https://github.com/search?q=repo%3Awesselt%2Fbunq2ynab+payee_id&type=code

  • Which version of bunq2ynab do you use?
  • When you run the script with -v verbose mode, does it POST or PATCH the transaction?
  • The transactions you listed in your original post have an unclosed } bracket (near "new": true), what does it really look like?
  • Which version of bunq2ynab do you use?

I uses this version: bunq-ynab-aws-lambda — version 1.4.4

  • When you run the script with -v verbose mode, does it POST or PATCH the transaction?

It is a POST transaction:

| DEBUG | bunq.py:160 | log_reply | ******************************
| INFO | bunq_api.py:176 | get_payments | Retrieved back to 2021-02-17...
| INFO | sync.py:190 | synchronize_account | Retrieved 2 bunq payments...
| DEBUG | zerofx.py:67 | merge | Merging ZeroFX duplicates...
| INFO | ynab.py:151 | upload_transactions | Creating transactions up to 2024-06-27...
| DEBUG | ynab.py:18 | log_request | ******************************
| DEBUG | ynab.py:19 | log_request | POST v1/budgets/f26d6114-6920-42a1-96df-9165c69ccce3/transactions
| DEBUG | ynab.py:21 | log_request |   Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| DEBUG | ynab.py:21 | log_request |   Content-type: application/json
| DEBUG | ynab.py:23 | log_request | -----
  • The transactions you listed in your original post have an unclosed } bracket (near "new": true), what does it really look like?

I edited the original post with the complete POST request.

Thanks for updating the post. You might want to remove "Bearer" log line, it contains a token which people can use to edit your YNAB budget.

It stands out to me that this is not valid JSON, I'd expect an opening bracket before "new" :)

},
"new": true,
"payee_id": "Incassorekening"
}
]

But that's not the problem. I do not maintain AWS versions, so that's going to be hard to troubleshoot.

What do you think of running the latest version of the script on a non-AWS install? Or a separate version of the script for each account you want to sync, so it doesn't try to create transfer transactions?

Im walking through the code. Found the wrong "transfer_payee_id" in 'syncpair'.

{'bunq_user_id': xxxxxx, 'bunq_user_name': 'xxxxx', 'bunq_account_id': xxxxxx, 'bunq_account_name': 'Gezamenlijke betaalrekening', 'iban': 'xxxxxxxxxxxx', 'balance': Decimal('12.71'), 'currency': 'EUR', 'status': 'ACTIVE', 'type': 'MonetaryAccountJoint', 'ynab_budget_id': 'f26d6114-6920-42a1-xxxxxxxxxxxxx', 'ynab_budget_name': 'My Budget', 'ynab_account_id': '1dcd1911-aaa6-44e0-9274-xxxxxxxxxx', 'ynab_account_name': 'Gezamenlijke betaalrekening', 'transfer_payee_id': 'Gezamenlijke betaalrekening'},

I will try to use a non-AWS install tonight :)

I think i accidentally edited the code and replaced a["transfer_payee_id"] with a["name"]

image

image