xero_invoices_create
Create invoices in Xero by specifying type, contact, and line items. Supports sales invoices (ACCREC) and bills (ACCPAY).
Instructions
Create a new invoice in Xero. Requires type, contact, and at least one line item.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| Type | Yes | Invoice type: ACCREC (sales invoice) or ACCPAY (bill) (required) | |
| ContactID | Yes | The contact ID to create the invoice for (required) | |
| LineItems | Yes | Array of line items (required). Each item needs Description, Quantity, UnitAmount, and AccountCode. | |
| Date | No | Invoice date in YYYY-MM-DD format | |
| DueDate | No | Due date in YYYY-MM-DD format | |
| Reference | No | Invoice reference/PO number | |
| Status | No | Initial invoice status (default: DRAFT) |
Implementation Reference
- src/domains/invoices.ts:53-119 (schema)Schema definition for the xero_invoices_create tool. Defines the input schema with required fields Type, ContactID, LineItems and optional fields Date, DueDate, Reference, Status.
{ name: "xero_invoices_create", description: "Create a new invoice in Xero. Requires type, contact, and at least one line item.", inputSchema: { type: "object", properties: { Type: { type: "string", enum: ["ACCREC", "ACCPAY"], description: "Invoice type: ACCREC (sales invoice) or ACCPAY (bill) (required)", }, ContactID: { type: "string", description: "The contact ID to create the invoice for (required)", }, LineItems: { type: "array", description: "Array of line items (required). Each item needs Description, Quantity, UnitAmount, and AccountCode.", items: { type: "object", properties: { Description: { type: "string", description: "Line item description", }, Quantity: { type: "number", description: "Quantity", }, UnitAmount: { type: "number", description: "Unit price", }, AccountCode: { type: "string", description: "Account code for the line item", }, TaxType: { type: "string", description: "Tax type code (e.g., OUTPUT, INPUT, NONE)", }, }, required: ["Description", "Quantity", "UnitAmount", "AccountCode"], }, }, Date: { type: "string", description: "Invoice date in YYYY-MM-DD format", }, DueDate: { type: "string", description: "Due date in YYYY-MM-DD format", }, Reference: { type: "string", description: "Invoice reference/PO number", }, Status: { type: "string", enum: ["DRAFT", "SUBMITTED", "AUTHORISED"], description: "Initial invoice status (default: DRAFT)", }, }, required: ["Type", "ContactID", "LineItems"], }, - src/domains/invoices.ts:205-233 (handler)Handler logic for xero_invoices_create. Extracts args, builds the invoice payload object, optionally adds optional fields, then POSTs to the Xero 'Invoices' endpoint and returns the response as JSON.
case "xero_invoices_create": { const { Type, ContactID, LineItems, Date, DueDate, Reference, Status } = args as { Type: string; ContactID: string; LineItems: unknown[]; Date?: string; DueDate?: string; Reference?: string; Status?: string; }; const invoice: Record<string, unknown> = { Type, Contact: { ContactID }, LineItems, }; if (Date) invoice.Date = Date; if (DueDate) invoice.DueDate = DueDate; if (Reference) invoice.Reference = Reference; if (Status) invoice.Status = Status; const response = await client.post("Invoices", { Invoices: [invoice], }); return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }], }; } - src/index.ts:31-31 (registration)Import of invoiceTools (which includes xero_invoices_create schema) and handleInvoiceTool from the invoices domain module into the main server.
import { invoiceTools, handleInvoiceTool } from "./domains/invoices.js"; - src/index.ts:258-259 (registration)Routing of tool calls starting with 'xero_invoices_' (including xero_invoices_create) to the handleInvoiceTool handler.
if (name.startsWith("xero_invoices_")) { return await handleInvoiceTool(name, toolArgs); - src/utils/client.ts:90-92 (helper)The XeroClient.post() method used by the handler to send the POST request to the Xero API.
async post(path: string, body: unknown): Promise<unknown> { return this.request("POST", path, undefined, body); }