npx @bryceo/me

Categorizing Amazon Purchases with Playwright

November 1, 2025

In today's age, it feels like I use Amazon for all purchases, ranging from foaming hand soap to a new pair of shoes and my biggest headache with Amazon is that every purchase processed by my bank is just listed as "Amazon". I am a budgetting adovcate, and so when my bank syncs to my budgetting tool(YNAB), all I see are a bunch of "Amazon" transactions and it makes it really difficult to categorize each purchase. The way I do is by combing through my purchase history and co-locate the purchase in YNAB so that I can sort them. This is a headache. I mean it really only takes a few minutes a day, but it is still annoying. So, I decided to work on automating this.

I reached for Playwright and Github Actions. This has been my go-to combo for any sort of web scraping because I am extremely familiar with and for my specific case, performance isn't an issue.

I found that I could search through all my Amazon transactions at https://www.amazon.com/cpe/yourpayments/transactions. So I use playwright to log into Amazon, go to this URL, and compile the data for each purchase. I store the date, total, orderId, and items where each item is the name of the product and the total eadh item cost. Additionally, I also need to track all refunds, so in some cases it is not an out-going purchase but an in-coming refund. I scrape the transaction history for the last 3 days.

I then use the YNAB API to get all transactions with "Amazon" in the title and no memo field in the transaction.

Comparing these two lists of data, I am able to match up each transaction in my budget with the transaction in my Amazon. After matching them, I POST to YNAB and update the budget item's memo with the relevant items purchased.

Now, with this script, I can simply use a schedule Github action to run every single day, keeping all my budget items in sync and allows me to manually categorize without having to match up my transactions.

All in all, its a few hundred lines of code, most of it parsing purchases on Amazon. But it has been incredibly helpful and has made one small headache in my life much more simple.