Skip to main content
Glama
marcusquinn

Amazon Order History CSV Download MCP

by marcusquinn

get_amazon_transactions

Fetch Amazon payment transactions for reconciliation, spending tracking, or accounting export by scraping the transactions page with date filters and region support.

Instructions

Fetch all Amazon payment transactions from the dedicated transactions page. Faster than per-order extraction as it scrapes the infinite-scroll transactions list. Returns: date, order IDs, amount, payment method, card info (last 4 digits), vendor. Useful for reconciling payments, tracking spending, or exporting for accounting.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
regionYesAmazon region code
start_dateNoStart date filter in ISO format (YYYY-MM-DD)
end_dateNoEnd date filter in ISO format (YYYY-MM-DD)
max_scrollsNoMaximum scroll attempts to load more transactions. Default: 50. Increase for longer history.

Implementation Reference

  • src/index.ts:382-410 (registration)
    Registration of the 'get_amazon_transactions' tool in the MCP tools array, including name, description, and input schema for region, date filters, and max_scrolls.
    { name: "get_amazon_transactions", description: "Fetch all Amazon payment transactions from the dedicated transactions page. Faster than per-order extraction as it scrapes the infinite-scroll transactions list. Returns: date, order IDs, amount, payment method, card info (last 4 digits), vendor. Useful for reconciling payments, tracking spending, or exporting for accounting.", inputSchema: { type: "object", properties: { region: { type: "string", description: "Amazon region code", enum: getRegionCodes(), }, start_date: { type: "string", description: "Start date filter in ISO format (YYYY-MM-DD)", }, end_date: { type: "string", description: "End date filter in ISO format (YYYY-MM-DD)", }, max_scrolls: { type: "number", description: "Maximum scroll attempts to load more transactions. Default: 50. Increase for longer history.", }, }, required: ["region"], }, },
  • MCP server request handler for 'get_amazon_transactions' tool call: validates input, retrieves browser page, invokes extractTransactionsFromPage with parameters, formats response as JSON with transaction data.
    case "get_amazon_transactions": { const regionParam = args?.region as string | undefined; const regionError = validateRegion(regionParam, args); if (regionError) return regionError; const region = regionParam!; const currentPage = await getPage(); const progressToken = request.params._meta?.progressToken; const startDate = args?.start_date as string | undefined; const endDate = args?.end_date as string | undefined; const maxScrolls = args?.max_scrolls as number | undefined; const transactions = await extractTransactionsFromPage( currentPage, region, { startDate: startDate ? new Date(startDate) : undefined, endDate: endDate ? new Date(endDate) : undefined, maxScrolls, onProgress: async (message, count) => { await sendProgress(progressToken, count, 0, message); }, }, ); return { content: [ { type: "text", text: JSON.stringify( { status: "success", params: { region, startDate, endDate, maxScrolls, }, transactionCount: transactions.length, transactions: transactions.map((t) => ({ date: t.date.toISOString(), orderIds: t.orderIds, amount: t.amount, cardInfo: t.cardInfo, vendor: t.vendor, })), }, null, 2, ), }, ], }; }
  • Primary handler implementation: Navigates to Amazon's transactions page, infinitely scrolls to load all transactions using Playwright, extracts transactions via multiple strategies (data-testid selectors and .transaction-date-container), deduplicates using mergeTransactions, applies date filtering, sorts by date descending, and reports progress.
    export async function extractTransactionsFromPage( page: Page, region: string, options?: { startDate?: Date; endDate?: Date; maxScrolls?: number; onProgress?: (message: string, count: number) => void; }, ): Promise<Transaction[]> { const regionConfig = getRegionByCode(region); const currency = regionConfig?.currency || "USD"; const url = getTransactionsPageUrl(region); const { startDate, endDate, maxScrolls = 50, onProgress } = options || {}; // Navigate to transactions page onProgress?.("Loading transactions page...", 0); await page.goto(url, { waitUntil: "domcontentloaded", timeout: 30000 }); // Wait for transactions to load await page .waitForSelector( '[data-testid="transaction-link"], .transaction-date-container, .transactions-line-item', { timeout: 10000 }, ) .catch(() => {}); // Give initial content time to render await page.waitForTimeout(1000); let allTransactions: Transaction[] = []; let previousCount = 0; let scrollCount = 0; let stableCount = 0; // Scroll to load all transactions while (scrollCount < maxScrolls) { // Extract current transactions const pageTransactions = await extractVisibleTransactions(page, currency); // Merge with existing (deduplicate) allTransactions = mergeTransactions(allTransactions, pageTransactions); onProgress?.( `Found ${allTransactions.length} transactions...`, allTransactions.length, ); // Check if we've stopped finding new transactions if (allTransactions.length === previousCount) { stableCount++; if (stableCount >= 3) { // No new transactions after 3 scroll attempts break; } } else { stableCount = 0; } previousCount = allTransactions.length; // Check date range - stop if we've gone past the start date if (startDate && allTransactions.length > 0) { const oldestDate = Math.min( ...allTransactions.map((t) => t.date.getTime()), ); if (oldestDate < startDate.getTime()) { break; } } // Scroll down to load more await scrollToLoadMore(page); scrollCount++; // Wait for new content await page.waitForTimeout(500); } // Filter by date range if specified let filteredTransactions = allTransactions; if (startDate || endDate) { filteredTransactions = allTransactions.filter((t) => { if (startDate && t.date < startDate) return false; if (endDate && t.date > endDate) return false; return true; }); } // Sort by date descending (newest first) filteredTransactions.sort((a, b) => b.date.getTime() - a.date.getTime()); onProgress?.( `Complete: ${filteredTransactions.length} transactions`, filteredTransactions.length, ); return filteredTransactions; }
  • Helper function to extract currently visible transactions from the page using fallback strategies: Strategy0 (date containers), Strategy1 (modern data-testid selectors), and generic parsing.
    async function extractVisibleTransactions( page: Page, currency: string, ): Promise<Transaction[]> { // Try Strategy 0 (transaction-date-container based) let transactions = await extractStrategy0(page, currency); if (transactions.length > 0) { return transactions; } // Try Strategy 1 (component-based parsing) transactions = await extractStrategy1(page, currency); if (transactions.length > 0) { return transactions; } // Fallback: generic extraction return extractGeneric(page, currency); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/marcusquinn/amazon-order-history-csv-download-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server