Starling + Python + YNAB - find transaction by import_id?

Hi there,

I'm creating a 'fire & forget' service in Python that can pick up Starling (UK) webhook v2 input, transform it to YNAB readable format and push it to YNAB.

Couple points to set context:

  • Starlings feed will sometimes push the same transaction multiple times (e.g. when the tx is authorized, when the tx is settled or when it is reversed 
  • I am using Starling's feedItemUid to fill YNAB's import_id field
  • I want my service to not maintain transactions (Starling is doing that, as well as YNAB), so I need to be able to find transactions based on the value of Starlings' feedItemUid (matching import_id in YNAB) and if it exists, I will PUT  /budgets/{budget_id}/transactions/{transaction_id} - if it does not exists I will POST /budgets/{budget_id}/transactions

To find the transactions, I'm currently doing a GET /budgets/{budget_id}/transactions and see if there's any transaction that has an import_id value which matches feedItemUid. It's not ideal and taking a bit of time to grab the data and iterate over it.

I have looked through the YNAB API docs, but there is no 'GET transaction by import_id' feature unfortunately - which would really help. In the ideal world it would return 200 and the transaction data or a 404 with an error. 

Anyone has a more efficient approach on how to do this with the current YNAB API?

Or is this something you guys can add to the API or have on the roadmap? 

2replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
  • Hey there! While we don't offer a way to GET transactions by import_id, there may be other ways you can narrow down the search. For example, you can specify a since_date parameter to only look at transactions on or after the date of the transaction you're trying to find, or use the /budgets/{budget_id}/accounts/{account_id}/transactions endpoint if you know the account the transaction would be in.

    It should also be noted that if you POST a transaction with the same import_id, YNAB will skip creating that transaction since it already exists. So, if you're confident that the transaction values won't change even if Starling pushes it multiple times, you can always POST and you won't get duplicates.

    If none of that works for you, though, you can definitely submit a feature request to add an import_id parameter to the GET transactions endpoints. Thanks for sharing what you're looking for!

    Like 1
  • Thanks Sarah, thanks for the answers, that's good to know.

    Starling is pushing new transactions and transaction changes in their feed and key values can certainly change, e.g. when you check in for the tube they'll do an authorisation for £0.10 on the card and settle that for the actual amount the next working day. 

    I've resorted to fetching the last 5 days of transactions, which definitely speeds the process up, but still not ideal. I might submit a feature request when I have the time.

Like Follow
  • 6 days agoLast active
  • 2Replies
  • 27Views
  • 2 Following