Get Instant Solutions for Kubernetes, Databases, Docker and more
Xero API is a powerful tool designed for developers to integrate Xero's accounting software capabilities into their applications. It enables seamless management of financial data, including invoicing, payments, and more, directly from your application.
When using the Xero API, you might encounter an error with the message DuplicateInvoiceNumber. This error typically arises during the creation of a new invoice.
While attempting to create an invoice, the API returns an error response indicating that the invoice number already exists.
The DuplicateInvoiceNumber error occurs because the invoice number you are trying to use is not unique. Xero requires each invoice to have a distinct number to maintain accurate records and avoid conflicts.
This issue often arises when invoice numbers are generated programmatically without checking for existing numbers in the Xero system.
To fix this issue, you need to ensure that each invoice number is unique. Here are the steps you can follow:
Before creating a new invoice, fetch the list of existing invoice numbers from Xero. You can use the following API call:
GET https://api.xero.com/api.xro/2.0/Invoices
Parse the response to extract all current invoice numbers.
Implement a logic in your application to generate a unique invoice number. You can append a timestamp or a unique identifier to ensure uniqueness. For example:
invoiceNumber = "INV-" + Date.now();
Before submitting the invoice creation request, check if the generated invoice number already exists in the list retrieved in step 1. If it does, regenerate the number.
For more information on handling invoices with Xero API, visit the Xero API Invoices Documentation.
For troubleshooting other common errors, refer to the Xero API Troubleshooting Guide.
(Perfect for DevOps & SREs)
Try Doctor Droid — your AI SRE that auto-triages alerts, debugs issues, and finds the root cause for you.