Search code examples
xero-apixero

Xero API - How to mark a credit note as sent once a payment has been made?


I'm using the xero-python SDK to send invoices and credit notes to my customers via email. Once I've sent an invoice/credit note, I wish to mark it as sent in Xero. I can do this for invoices by doing the following:

updated_invoice = Invoice(sent_to_contact=True)
invoices = Invoices(invoices=[updated_invoice])

api_instance.update_invoice(TENANT_ID, invoice.invoice_id, invoices)

This works with no issue, even if the invoice has a payment against it. In the history in Xero it notes that the edit came after the payment:

Date User Action Detail
14 Nov 2024 10:13 am System Generated Edited Received through the Xero API from Email testing
14 Nov 2024 10:12 am System Generated Paid Payment received from Joe Morgan on 14 November 2024 for 11.05. This invoice has been fully paid

However, when I try and replicate this for credit notes, I get the following error - This document cannot be edited as it has a payment or credit note allocated to it.

The code below follows the Python API docs:

 updated_credit_note = CreditNote(sent_to_contact=True)
credit_notes = CreditNotes(credit_notes=[updated_credit_note])

api_instance.update_credit_note(TENANT_ID, credit_note.credit_note_id, credit_notes)

Having read through docs, I understand that this might be expected behaviour, as there is a payment against the credit note. This uservoice post from 2011 states that invoices and credit notes can only be edited before they're marked as paid, which is also how the GUI handles it. However, I've demonstrated that you can mark invoices as sent via the API after a payment has been made. It's also possible to mark credit notes as sent in the GUI after a payment has been made.

Is this a limitation of the API, and if so is there a workaround? Or am I making an incorrect API call when attempting to update the credit note?


Solution

  • The API was updated so that you can edit paid ACCREC invoices but this has not been extended to ACCPAY invoices or any type of credit note