create-timesheet
Create payroll timesheets in Xero by specifying employee details, calendar periods, and work hours to track and manage employee time for accurate payroll processing.
Instructions
Create a new payroll timesheet in Xero. This allows you to specify details such as the employee ID, payroll calendar ID, start and end dates, and timesheet lines.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| payrollCalendarID | Yes | The ID of the payroll calendar. | |
| employeeID | Yes | The ID of the employee. | |
| startDate | Yes | The start date of the timesheet period (YYYY-MM-DD). | |
| endDate | Yes | The end date of the timesheet period (YYYY-MM-DD). | |
| timesheetLines | No | The lines of the timesheet. |
Implementation Reference
- The primary handler function that handles the creation of a Xero payroll timesheet, including error handling and calling the inner API function.export async function createXeroPayrollTimesheet(timesheet: Timesheet): Promise< XeroClientResponse<Timesheet | null> > { try { const newTimesheet = await createTimesheet(timesheet); return { result: newTimesheet, isError: false, error: null, }; } catch (error) { return { result: null, isError: true, error: formatError(error), }; } }
- Zod schema defining the input parameters for the 'create-timesheet' tool.{ payrollCalendarID: z.string().describe("The ID of the payroll calendar."), employeeID: z.string().describe("The ID of the employee."), startDate: z.string().describe("The start date of the timesheet period (YYYY-MM-DD)."), endDate: z.string().describe("The end date of the timesheet period (YYYY-MM-DD)."), timesheetLines: z .array( 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)."), }) ) .optional() .describe("The lines of the timesheet."), },
- src/tools/create/index.ts:13-25 (registration)The 'create-timesheet' tool is registered by including CreatePayrollTimesheetTool in the CreateTools export array.export const CreateTools = [ CreateContactTool, CreateCreditNoteTool, CreateManualJournalTool, CreateInvoiceTool, CreateQuoteTool, CreatePaymentTool, CreateItemTool, CreateBankTransactionTool, CreatePayrollTimesheetTool, CreateTrackingCategoryTool, CreateTrackingOptionsTool ];
- Tool definition using CreateXeroTool helper, naming it 'create-timesheet', providing schema, description, and wrapper logic around the handler.const CreatePayrollTimesheetTool = CreateXeroTool( "create-timesheet", `Create a new payroll timesheet in Xero. This allows you to specify details such as the employee ID, payroll calendar ID, start and end dates, and timesheet lines.`, { payrollCalendarID: z.string().describe("The ID of the payroll calendar."), employeeID: z.string().describe("The ID of the employee."), startDate: z.string().describe("The start date of the timesheet period (YYYY-MM-DD)."), endDate: z.string().describe("The end date of the timesheet period (YYYY-MM-DD)."), timesheetLines: z .array( 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)."), }) ) .optional() .describe("The lines of the timesheet."), }, async (params: Timesheet) => { const response = await createXeroPayrollTimesheet(params); if (response.isError) { return { content: [ { type: "text" as const, text: `Error creating timesheet: ${response.error}`, }, ], }; } const timesheet = response.result; return { content: [ { type: "text" as const, text: `Successfully created timesheet with ID: ${timesheet?.timesheetID}`, }, ], }; }, );