The xero-node SDK provides a comprehensive client for interacting with the Xero APIs (Accounting, Assets, Bankfeeds, Files, Projects, Payroll AU/NZ/UK) using Node.js. It facilitates OAuth 2.0 authentication and API requests, simplifying integration for developers building applications that connect with Xero accounting data. The library is currently in its 15.0.0 major version, with frequent updates (multiple minor/patch releases per month, and major releases roughly every few months) to reflect changes in the underlying Xero API and add new features. Key differentiators include full API coverage across multiple Xero API sets and robust TypeScript support, making it suitable for enterprise-grade integrations requiring strong typing and reliability.
npm install xero-nodeVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing the XeroClient, managing an access token (refreshing if expired), and making a basic API call to fetch contacts. Requires valid Xero API credentials and an existing tenant ID.
Review your `Employee` and `Employment` object payloads for Payroll NZ and UK. Ensure all newly required fields are populated before making API calls. Refer to the official Xero API documentation for the exact schema.
Migrate your code to use the supported alternatives for employee management. Consult the Xero API documentation or the Payroll API clients (e.g., `PayrollAuApi`, `PayrollNzApi`, `PayrollUkApi`) for the correct methods.
When calling `xero.filesApi.getFiles()`, ensure you provide the `direction` parameter, typically with a value like `'asc'` or `'desc'` to specify sorting order.
Implement robust token storage and refresh logic. The `xero-node` client provides `setTokenSet` and `refreshToken` methods. You should store the `refresh_token` securely and use it to obtain new access tokens when the current one expires.
After successful authentication, the `xeroClient.tenantIds` array will contain the IDs of the organizations the user has granted access to. Always pass the relevant `tenantId` (e.g., `xeroClient.tenantIds[0]`) as the first argument to API methods like `getContacts`, `createInvoices`, etc.
Ensure you have completed the OAuth 2.0 authentication flow correctly, retrieved a valid access token, and are setting it on the `XeroClient`. Implement token refresh logic to get a new access token using your refresh token before making requests with an expired token.
Verify that your request body adheres to the Xero API schema for the specific endpoint. Ensure all required fields for the entity type are present and correctly formatted. For example, when creating a contact, `contacts: [{ name: '...' }]` is expected.Explicitly cast your object to the correct type (e.g., `const newContact: Contact = { name: 'Test Contact' };`) or ensure your object strictly matches the model's interface, including all required properties as defined in `xero-node/dist/gen/model/accounting/contact.d.ts`.No dependency data recorded yet.