0

I'm creating a bill (supplier invoice) in Xero API (C# .Net). Everything populates perfectly except for the Reference number which remains blank.

Excerpt:

var invoiceObject = new Invoice
{
    Reference = "TEST123", 
    Contact = contact,
    Date = DateTime.Now,
    DueDate = DateTime.Now,
    ExpectedPaymentDate = DateTime.Now,
    Status = Xero.Api.Core.Model.Status.InvoiceStatus.Draft,
    LineItems = lineItems,
    Type = Xero.Api.Core.Model.Types.InvoiceType.AccountsPayable
};

var invoice = api.Invoices.Create(invoiceObject);

The following screenshot demonstrates the issue:

Screenshot of issue

Every other field, lineitem, tax code, etc. populates perfectly.

I've tried different combinations of upper and lowercase characters, numbers, etc. but it doesn't work.

If I log in to Xero, open the Invoice and manually enter TEST123 an save the invoice, it works perfectly.

I've also tried saving the invoice, then editing it and re-saving in the API and the reference still does not populate.

How can I set the reference in the API?

SimonGoldstone
  • 5,096
  • 3
  • 27
  • 38

2 Answers2

1

Quick answer

Xero Invoice API docs indicate that you can't set the reference value for an ACCPAY invoice, but that whatever you put for the Invoice Number (which is a non-unique field on ACCPAY Invoices) will also appear in the reference field.

Explanation

I ran into this same issue. I found this comment on Xero's support forum:

https://community.xero.com/developer/discussion/40489223

... which says this:

Reference is presently slightly differently based on whether the invoice is a sales invoice (ACCREC) or a purchase invoice/bill (ACCPAY). For a bill the reference is presented in the InvoiceNumber element, check our documentation on invoices here where we explain this in more detail.


From the linked to docs

Invoice API Doc notes

All that said, the screenshot you include in your post does have a "reference" input on it, but that's not an input for the invoice's reference value - that's an input for a possible reference value for a payment you enter against the invoice. The reference value for an invoice appears at the top next to the due date:

enter image description here

Daniel L
  • 614
  • 6
  • 7
1

I have the exact same issue. I'm using Python Xero but hopefully, it is the same for Javascript.

In my case, I have to use InvoiceNumber instead of Reference for bills.

Yinzheng
  • 11
  • 1