get_amazon_gift_card_transactions
Retrieve detailed Amazon gift card transaction history including current balance, transaction dates, amounts, and order IDs. Supports multiple regions and pagination for complete records.
Instructions
Get Amazon gift card transaction history with full details. Returns: current balance, transaction count, and detailed transactions (date, description, amount, closing balance, transaction type, order ID, claim code, serial number). Supports pagination for complete history.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| region | Yes | Amazon region code | |
| max_pages | No | Maximum pages of transaction history to fetch. Default: 10. Set to 0 for unlimited. |
Implementation Reference
- src/index.ts:466-487 (registration)Tool registration in the MCP tools array, including name, description, and input schema definition.{ name: "get_amazon_gift_card_transactions", description: "Get Amazon gift card transaction history with full details. Returns: current balance, transaction count, and detailed transactions (date, description, amount, closing balance, transaction type, order ID, claim code, serial number). Supports pagination for complete history.", inputSchema: { type: "object", properties: { region: { type: "string", description: "Amazon region code", enum: getRegionCodes(), }, max_pages: { type: "number", description: "Maximum pages of transaction history to fetch. Default: 10. Set to 0 for unlimited.", default: 10, }, }, required: ["region"], }, },
- src/index.ts:1319-1356 (handler)Dispatch handler for the tool call: validates region, calls extractGiftCardData, formats output with helper, returns JSON response.case "get_amazon_gift_card_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 maxPages = (args?.max_pages as number) ?? 10; // Extract gift card transactions const giftCardData = await extractGiftCardData(currentPage, region, { maxPages, fetchAllPages: true, }); // Convert to export format using shared helper const exportData = formatGiftCardDataForExport(giftCardData); return { content: [ { type: "text", text: JSON.stringify( { status: "success", params: { region, maxPages, }, ...exportData, }, null, 2, ), }, ], }; }
- Core implementation: navigates to gift card balance page, extracts current balance, handles pagination through transaction history, parses table rows for transaction details using Playwright.export async function extractGiftCardData( page: Page, region: string, options: GiftCardExtractionOptions = {}, ): Promise<GiftCardData> { const { maxPages = 10, fetchAllPages = true } = options; const regionConfig = getRegionByCode(region); const currency = regionConfig?.currency || "USD"; const url = getGiftCardPageUrl(region); // Navigate to gift card balance page await page.goto(url, { waitUntil: "domcontentloaded", timeout: 30000 }); // Wait for the balance table to load await page .waitForSelector( 'table.a-bordered tbody tr, [data-testid="gc-balance"], #gc-balance', { timeout: 10000 }, ) .catch(() => {}); // Extract balance (from first row's closing balance, or dedicated element) const balance = await extractBalance(page, currency); // Extract transactions from all pages const allTransactions: GiftCardTransaction[] = []; let pageCount = 0; let hasMorePages = true; while (hasMorePages) { pageCount++; // Extract transactions from current page const pageTransactions = await extractTransactionsFromTable(page, currency); allTransactions.push(...pageTransactions); // Check if we should continue to next page if (!fetchAllPages) { hasMorePages = false; continue; } if (maxPages > 0 && pageCount >= maxPages) { hasMorePages = false; continue; } // Check for and click "Next" pagination button hasMorePages = await goToNextGiftCardPage(page); // Wait for the new page content to load await page.waitForTimeout(500); await page .waitForSelector("table.a-bordered tbody tr", { timeout: 5000 }) .catch(() => {}); } // Deduplicate transactions (in case of overlap between pages) const uniqueTransactions = deduplicateTransactions(allTransactions); return { balance, transactions: uniqueTransactions, region, }; }
- src/index.ts:583-616 (helper)Helper function to format GiftCardData into standardized export structure for JSON response.function formatGiftCardDataForExport( giftCardData: GiftCardData, ): GiftCardExportData { return { balance: { amount: giftCardData.balance.balance.amount, currency: giftCardData.balance.balance.currency, formatted: giftCardData.balance.balance.formatted, }, lastUpdated: giftCardData.balance.lastUpdated.toISOString(), region: giftCardData.region, transactionCount: giftCardData.transactions.length, transactions: giftCardData.transactions.map((t) => ({ date: t.date.toISOString(), description: t.description, amount: { amount: t.amount.amount, currency: t.amount.currency, currencySymbol: t.amount.currencySymbol, formatted: t.amount.formatted, }, closingBalance: { amount: t.closingBalance.amount, currency: t.closingBalance.currency, currencySymbol: t.closingBalance.currencySymbol, formatted: t.closingBalance.formatted, }, type: t.type, orderId: t.orderId, claimCode: t.claimCode, serialNumber: t.serialNumber, })), }; }
- TypeScript interface defining the output structure of gift card data, used for type safety and documentation.export interface GiftCardData { /** Current gift card balance */ balance: GiftCardBalance; /** Transaction history */ transactions: GiftCardTransaction[]; /** Region this data was extracted from */ region: string; }