I won 2nd prize in an algorithm development contest at office few months ago and won a voucher for 7500/-
The voucher could be redeemed against any food bill. I kept it for few weeks hoping to rake up a big bill from some party but didn’t find one. Mohit pointed out that Swiggy bills would also count towards this. I do order out regularly and suspected that I might have enough bills from after the voucher issue date.
However, to verify this, I’d have to do quite a bit of manual effort. At an average price of 150/- per order, I’d have to trace back around 50 orders to confirm if the bills totalled to 7500/-
The swiggy android app shows 2.5 orders per screen. That’s a lot of scrolling and I’d need to switch to calculator app to add. It’s time consuming and not really an efficient way.

I tried asking Swiggy themselves but the chat support couldn’t help either. (To be honest, Zomato chat has lowered the bar on customer service so much, even this failed communication with Swiggy came as a pleasant surprise)
Next, I opened their website in Chrome and it showed 5 orders on the front screen. However, there was a button to load more and it worked flawlessly. 10 clicks and few seconds later, I had all the 50 orders in one scroll-able window. At this point in time, I tried my luck with basic excel and editing commands. I pressed (Ctrl+A) on the website, and (Ctrl+V) on an excel cell and hit jackpot. The entire website content got pasted in 2000 rows and 1 column in editable format! Few manipulations later, I had a neat summary of the orders with date and amount.
Guess what? The orders did total up to the voucher value. A total of 35 orders.
So far, good. Next, I needed printed copies of all the 35 invoices. This proved a bit difficult for two reasons.
One, I don’t receive an email with a downloadable invoice copy from Swiggy upon order completion. (Maybe, there’s a send invoice option which I may have disabled, but in either case, it’s not gonna help me out with past orders). So any email automation option goes right out the window.
Two, invoices are available on the desktop website, but they’re buried behind few clicks and there’s no bulk download invoice option. Every order has an individual “View Details” button, which when clicked, opens a new screen in 1/3rd of the window with a button “Invoice” that downloads the receipt.
To download all 35 invoices, I’d need some really good browser automation tools. (I knew this is possible in Python from the time when Abhishek tricked an office poll into accepting 100s of entries of my name for a peer nominated award)

I started looking up browser automation tools and came across the Chrome ‘Web Scraper‘ extension tool. I was pleasantly surprised at the potential of this tool to make my life easy. It took an hour or two of watching free tutorials and I got started. I made decent progress and extracted all the restaurants’ names and Order IDs in a csv within moments.


Getting to the invoices, however, was proving just a tad difficult and I was about to deep dive into the tutorials once again when I noticed this little piece of information; and it changed everything. (Yellow arrow)

The URL, that the invoice button was pointing to, was a static text followed by the Order ID! (https://www.swiggy.com/invoice/download/xxxxxxxxxx) This wasn’t a security flaw as I was able to only access the invoices which were available in my account.
I already had the Order IDs and now, all I had to do was write a 4 line VBA code to open the links! (I knew this from the time I wrote a similar macro to read multiple patents easily while working at LexInnova).

Here’s the result:


And I thought this was it.
But another small hurdle was figuring out how to print 35 PDF files. I selected all 35 files, right-clicked to see if there was a Print option, but there wasn’t. I was about to prepare myself for the next sprint on figuring out how to print multiple PDFs when I found out that Windows/ Adobe lets you print a maximum of 10 PDFs at once.
I selected 10 PDFs, right – clicked and sure enough, there was a print option. 4 clicks later, I was able to submit the bills to my office.
Thanks for reading 🙂
5 replies on “Technical exploration & building an automation to bulk download invoices from the Swiggy app”
Cool Stuff. There’s a free tool called SAM Pdf. It lets you merge/extract/edit multiple pdfs with ease. Use that as your final steps & you’re good to go!
LikeLiked by 1 person
Will do!
LikeLike
[…] is organized neatly and accessible easily. I used the webscraper.io Chrome extension. I already had experience with scraping swiggy using this tool, so it was straight forward enough to setup. For someone […]
LikeLike
Hi! The Swiggy website has changed a lot in the past few years. The link shared by you above, no longer works.
Is there any way around for the new and “improved” website. Thanks!!!
LikeLike
I checked just now. Yes – they no longer have the invoices available on the website. However, they email the invoice from a simple button click on the orders page. It’s a simple task – you can download the webscraper sitemap and upload+modify it to click the relevant buttons. I checked, it will still work as the page and HTML tags are still static.
Once you’ve emailed yourself all the invoices, it’s another simple Gapps script to download all email attachments into one folder for saving/ printing.
I can modify the sitemap and write the Gapps script for you. I can be hired here: https://www.upwork.com/services/product/development-it-an-excel-workbook-spreadsheet-with-dashboards-kpis-formulae-charts-1398902996638670848?ref=project_share&tier=1
LikeLike