Bulk Approve Transactions
ynab_bulk_approve_transactionsApprove multiple YNAB transactions simultaneously in a single API call by providing an array of transaction IDs.
Instructions
Approves multiple transactions at once. Provide an array of transaction IDs to approve them all in a single API call.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| budgetId | No | The ID of the budget (optional, defaults to YNAB_BUDGET_ID environment variable) | |
| transactionIds | Yes | Array of transaction IDs to approve |
Implementation Reference
- The execute function that handles the bulk approve transactions logic. It maps transaction IDs to approved:true, calls api.transactions.updateTransactions, formats the response, and returns a success/error result.
export async function execute(input: BulkApproveTransactionsInput, api: ynab.API) { try { const budgetId = getBudgetId(input.budgetId); if (!input.transactionIds || input.transactionIds.length === 0) { throw new Error("No transaction IDs provided"); } // Build the update transactions array const transactions: ynab.SaveTransactionWithIdOrImportId[] = input.transactionIds.map((id) => ({ id, approved: true, })); const response = await api.transactions.updateTransactions(budgetId, { transactions, }); if (!response.data.transactions) { throw new Error("Failed to update transactions - no transaction data returned"); } const updatedTransactions = response.data.transactions.map((txn) => ({ id: txn.id, date: txn.date, amount: (txn.amount / 1000).toFixed(2), payee_name: txn.payee_name, approved: txn.approved, })); return { content: [{ type: "text" as const, text: JSON.stringify({ success: true, approved_count: updatedTransactions.length, transactions: updatedTransactions, message: `Successfully approved ${updatedTransactions.length} transaction(s)`, }, null, 2), }], }; } catch (error) { console.error("Error bulk approving transactions:", error); return { content: [{ type: "text" as const, text: JSON.stringify({ success: false, error: getErrorMessage(error), }, null, 2), }], }; } } - Exported name, description, and input schema (budgetId optional string, transactionIds array of strings) for the tool.
export const name = "ynab_bulk_approve_transactions"; export const description = "Approves multiple transactions at once. Provide an array of transaction IDs to approve them all in a single API call."; export const inputSchema = { budgetId: z.string().optional().describe("The ID of the budget (optional, defaults to YNAB_BUDGET_ID environment variable)"), transactionIds: z.array(z.string()).describe("Array of transaction IDs to approve"), }; - Helper function getBudgetId that resolves the budget ID from input or the YNAB_BUDGET_ID environment variable.
function getBudgetId(inputBudgetId?: string): string { const budgetId = inputBudgetId || process.env.YNAB_BUDGET_ID || ""; if (!budgetId) { throw new Error("No budget ID provided. Please provide a budget ID or set the YNAB_BUDGET_ID environment variable."); } return budgetId; } - src/index.ts:75-79 (registration)Registration of the tool on the MCP server using server.registerTool with the name 'ynab_bulk_approve_transactions'.
server.registerTool(BulkApproveTransactionsTool.name, { title: "Bulk Approve Transactions", description: BulkApproveTransactionsTool.description, inputSchema: BulkApproveTransactionsTool.inputSchema, }, async (input) => BulkApproveTransactionsTool.execute(input, api)); - src/index.ts:14-14 (registration)Import of BulkApproveTransactionsTool module.
import * as BulkApproveTransactionsTool from "./tools/BulkApproveTransactionsTool.js";