Skip to main content
Glama
XeroAPI

Xero MCP Server

Official

add-timesheet-line

Add work hours to an existing payroll timesheet in Xero by specifying earnings rate, units, and date for accurate time tracking.

Instructions

Add a new timesheet line to an existing payroll timesheet in Xero.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timesheetIDYesThe ID of the timesheet to update.
timesheetLineYesThe details of the timesheet line to add.

Implementation Reference

  • The primary handler function for adding a timesheet line to a Xero payroll timesheet. It calls the internal addTimesheetLine helper and wraps the result in a standard XeroClientResponse, handling errors appropriately.
    export async function updateXeroPayrollTimesheetAddLine(timesheetID: string, timesheetLine: TimesheetLine): Promise< XeroClientResponse<TimesheetLine | null> > { try { const newLine = await addTimesheetLine(timesheetID, timesheetLine); return { result: newLine, isError: false, error: null, }; } catch (error) { return { result: null, isError: true, error: formatError(error), }; } }
  • Helper function that authenticates the Xero client and calls the Payroll NZ API to create a new timesheet line.
    async function addTimesheetLine(timesheetID: string, timesheetLine: TimesheetLine): Promise<TimesheetLine | null> { await xeroClient.authenticate(); // Call the createTimesheetLine endpoint from the PayrollNZApi const createdLine = await xeroClient.payrollNZApi.createTimesheetLine( xeroClient.tenantId, timesheetID, timesheetLine, ); return createdLine.body.timesheetLine ?? null; }
  • Registers the "add-timesheet-line" tool using CreateXeroTool, defines the input schema, and provides the execution wrapper that calls the handler and formats the MCP response.
    const AddTimesheetLineTool = CreateXeroTool( "add-timesheet-line", `Add a new timesheet line to an existing payroll timesheet in Xero.`, { timesheetID: z.string().describe("The ID of the timesheet to update."), timesheetLine: z.object({ earningsRateID: z.string().describe("The ID of the earnings rate."), numberOfUnits: z.number().describe("The number of units for the timesheet line."), date: z.string().describe("The date for the timesheet line (YYYY-MM-DD)."), }).describe("The details of the timesheet line to add."), }, async (params: { timesheetID: string; timesheetLine: TimesheetLine }) => { const { timesheetID, timesheetLine } = params; const response = await updateXeroPayrollTimesheetAddLine(timesheetID, timesheetLine); if (response.isError) { return { content: [ { type: "text" as const, text: `Error adding timesheet line: ${response.error}`, }, ], }; } const newLine = response.result; return { content: [ { type: "text" as const, text: `Successfully added timesheet line with date: ${newLine?.date}`, }, ], }; }, );

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/XeroAPI/xero-mcp-server'

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