Importing transfers between accounts

Hi there,

I'm working on an import/syncing script of mine that uses the /budgets/{budget_id}/transactions POST API to create transactions based on account listing opbtained from my bank API.

I'm able to detect transfers between checking accounts that both are tracked in YNAB and are attempting to automatically create a YNAB transfer between these two accounts. However, I'm struggeling. I can obviously create the transaction, but it does not seem to be willing to link the two accounts - in spite of adding the correct id of the other account in the transaction:

{'account_id': '7103df7c-FAKE-4d24-0000-ed6d168497b8',
 'account_name': None,
 'amount': -150000,
 'approved': False,
 'category_id': None,
 'category_name': None,
 'cleared': 'uncleared',
 'date': '2019-07-27',
 'flag_color': None,
 'id': None,
 'import_id': 'YNAB:-150000:2019-07-27:1',
 'memo': 'Overføring til annen egen konto: Brukskonto',
 'payee_id': None,
 'payee_name': None,
 'subtransactions': None,
 'transfer_account_id': '1a5ca2f7-FAKW-47f6-0000-65766858e813'}

The "undocumented" property here is the last one:

'transfer_account_id': '1a5ca2f7-FAKW-47f6-0000-65766858e813'

The transfer_account_id is the ID of the other account that the money is transferred to in this case.

I've also tried creating the transaction with a payee_name set, but this only creates a new payee - not a transfer between accounts. It seems I have to manually edit the transactions in YNAB after the import.

Anyone having any idea about this?

5replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Hi there Sten - It sounds like you are trying to create a transfer between 2 accounts through the API.  You'll want to specify the payee_id field as the transfer payee pointing to the other account.  To get the transfer payee id you can GET /budgets/{budget_id}/accounts to list accounts and note the transfer_payee_id for an account.  

    For example, let's say you are trying to create a transfer transaction from account A to account B.  First, GET /budgets/{budget_id}/accounts to list your accounts and then note the transfer_payee_id  for account B.  Then, POST to /budgets/{budget_id}/transactions and specify the account_id as account A's account ID (source) and the payee_id as the transfer_payee_id for account B.

    I'll update the documentation for payee_id on  POST /budgets/{budget_id}/transactions to make this clearer.

    Hope this helps!

    Like 1
  • That seems to be working perfectly! Thanks, yes that helped!

  • This is pretty cool.  Is there a reason why only one side of the transaction gets a flag when flag_color is set?

    • mydran It's the same behavior as the web and mobile apps - changing flag on one side does not change it on the other side. 

      • mydran
      • mydran
      • 9 mths ago
      • 1
      • Reported - view

      @Brady,  sorry I wondered more on the use case for only flagging one side of a transaction as cleared/flagged, when both sides of the transaction are entered in at the same time via the method you described above. 

      The more I pondered on it I came to realise that not all transactions more between all accounts instantly - so I can understand now why it behaves this way.

      Thanks for taking the time to reply  :)

      Like 1
Like Follow
  • 9 mths agoLast active
  • 5Replies
  • 183Views
  • 3 Following