approve-timesheet
Approve payroll timesheets in Xero using their unique ID to finalize employee time tracking and processing.
Instructions
Approve a payroll timesheet in Xero by its ID.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| timesheetID | Yes | The ID of the timesheet to approve. |
Implementation Reference
- Defines and implements the 'approve-timesheet' MCP tool handler, including schema validation and response formatting. Delegates to core Xero handler.const ApprovePayrollTimesheetTool = CreateXeroTool( "approve-timesheet", `Approve a payroll timesheet in Xero by its ID.`, { timesheetID: z.string().describe("The ID of the timesheet to approve."), }, async (params: { timesheetID: string }) => { const { timesheetID } = params; const response = await approveXeroPayrollTimesheet(timesheetID); if (response.isError) { return { content: [ { type: "text" as const, text: `Error approving timesheet: ${response.error}`, }, ], }; } const timesheet = response.result; return { content: [ { type: "text" as const, text: `Successfully approved timesheet with ID: ${timesheet?.timesheetID}`, }, ], }; }, );
- Core handler function that wraps the Xero API approval call, handles errors, and returns structured response.export async function approveXeroPayrollTimesheet(timesheetID: string): Promise< XeroClientResponse<Timesheet | null> > { try { const approvedTimesheet = await approveTimesheet(timesheetID); return { result: approvedTimesheet, isError: false, error: null, }; } catch (error) { return { result: null, isError: true, error: formatError(error), }; } }
- Helper function that authenticates and directly calls the Xero Payroll NZ API to approve the timesheet.async function approveTimesheet(timesheetID: string): Promise<Timesheet | null> { await xeroClient.authenticate(); // Call the approveTimesheet endpoint from the PayrollNZApi const approvedTimesheet = await xeroClient.payrollNZApi.approveTimesheet( xeroClient.tenantId, timesheetID, ); return approvedTimesheet.body.timesheet ?? null; }
- Input schema using Zod for validating the timesheetID parameter.{ timesheetID: z.string().describe("The ID of the timesheet to approve."), },
- src/tools/update/index.ts:16-30 (registration)Registers the approve-timesheet tool (ApprovePayrollTimesheetTool) within the UpdateTools array.export const UpdateTools = [ UpdateContactTool, UpdateCreditNoteTool, UpdateInvoiceTool, UpdateManualJournalTool, UpdateQuoteTool, UpdateItemTool, UpdateBankTransactionTool, ApprovePayrollTimesheetTool, AddTimesheetLineTool, UpdatePayrollTimesheetLineTool, RevertPayrollTimesheetTool, UpdateTrackingCategoryTool, UpdateTrackingOptionsTool ];