Skip to content

Instantly share code, notes, and snippets.

@ashkulz
Created November 8, 2025 11:32
Show Gist options
  • Select an option

  • Save ashkulz/7fcf0b6986bd7da25db845ebcf7ffef4 to your computer and use it in GitHub Desktop.

Select an option

Save ashkulz/7fcf0b6986bd7da25db845ebcf7ffef4 to your computer and use it in GitHub Desktop.
Download transactions from Amazon Pay India
# Works as of Nov 2025
import csv, lxml.etree, requests
# These headers have to match what the browser sends, there's some checksum as otherwise you get a 503:
def get_amazon_pay_chunk(cookie, start, end):
url = f"https://www.amazon.in/pay/history/ajax?requestParams=%7B%22indexParams%22%3A%22%7B%5C%22P3_TH%5C%22%3A%7B%5C%22startKey%5C%22%3A{start}%2C%5C%22lastKey%5C%22%3A{end}%7D%7D%22%2C%22queryFilters%22%3A%7B%22transactionTypes%22%3A%5B%5D%7D%7D"
return requests.get(url, headers={
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:144.0) Gecko/20100101 Firefox/144.0",
"Accept": "application/json, text/javascript, */*; q=0.01",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"X-Requested-With": "XMLHttpRequest",
"Referer": "https://www.amazon.in/pay/history",
"Cookie": cookie,
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"TE": "trailers",
}).json()
cookie = '' # open Dev Tools => Network tab => Right click any request => Copy Value => Copy request headers and copy value for "Cookie"
index = 0
result = []
last = None
while True:
start = index * 20
chunk = get_amazon_pay_chunk(cookie, start, start + 19)
divtx = lxml.etree.HTML(chunk['transactionsHtml']).xpath("//div[@data-a-expander-name='transaction-desktop']")
data = [[column.text.strip() for column in row.xpath(".//span[contains(@class, 'a-size-medium') or contains(@class, 'a-size-base')]")] for row in divtx]
if data[-1][-2] == last:
break
last = data[-1][-2]
result.extend(data)
with open('amazon_pay.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["Narration", "Source", "Date/Time", "Amount", "Status"])
for row in result:
writer.writerow([c.replace(' ₹', '').replace('₹', '') for c in row])
print(f"\rChunk: {index + 1} Last: {last}\t\t\t", end='')
if not chunk['hasMoreToFollow']:
break
index += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment