0

I am getting a validation error from the Xero API:

Invoice not of valid status for modification

The message is too generic, and we have no idea why we are getting it or how to fix it.

I've tried different status values:

  • DRAFT
  • AUTHORISED

But I get the same response:

{
  "ErrorNumber": 10,
  "Type": "ValidationException",
  "Message": "A validation exception occurred",
  "Elements": [
    {
      "Type": "ACCPAY",
      "InvoiceID": "1cb8f5c6-xxxx-xxxx-xxxx-9ca48a1cac06",
      "InvoiceNumber": "CS-001854",
      "Payments": [],
      "CreditNotes": [],
      "Prepayments": [],
      "Overpayments": [],
      "AmountDue": 1350.00,
      "HasErrors": true,
      "IsDiscounted": false,
      "Attachments": [],
      "Contact": {
        "ContactID": "3dd542c0-xxxx-xxxx-xxxx-176cc1c484d8",
        "Addresses": [],
        "Phones": [],
        "ContactGroups": [],
        "SalesTrackingCategories": [],
        "PurchasesTrackingCategories": [],
        "ContactPersons": [],
        "Attachments": [],
        "HasValidationErrors": false,
        "ValidationErrors": [],
        "Warnings": []
      },
      "DateString": "2018-08-31T00:00:00",
      "Date": "\/Date(1535673600000+0000)\/",
      "DueDateString": "2018-09-14T00:00:00",
      "DueDate": "\/Date(1536883200000+0000)\/",
      "Status": "DRAFT",
      "LineAmountTypes": "Exclusive",
      "LineItems": [
        {
          "Description": "Services",
          "UnitAmount": 450.00,
          "TaxType": "NONE",
          "TaxAmount": 0.00,
          "LineAmount": 450.00,
          "AccountCode": "6021",
          "Tracking": [],
          "Quantity": 1.0000,
          "ValidationErrors": [],
          "Warnings": []
        },
        {
          "Description": "Services",
          "UnitAmount": 450.00,
          "TaxType": "NONE",
          "TaxAmount": 0.00,
          "LineAmount": 450.00,
          "AccountCode": "6021",
          "Tracking": [],
          "Quantity": 1.0000,
          "ValidationErrors": [],
          "Warnings": []
        },
        {
          "Description": "Services",
          "UnitAmount": 450.00,
          "TaxType": "NONE",
          "TaxAmount": 0.00,
          "LineAmount": 450.00,
          "AccountCode": "6021",
          "Tracking": [],
          "Quantity": 1.0000,
          "ValidationErrors": [],
          "Warnings": []
        }
      ],
      "SubTotal": 1350.00,
      "TotalTax": 0.00,
      "Total": 1350.00,
      "CurrencyCode": "GBP",
      "ValidationErrors": [
        {
          "Message": "Invoice not of valid status for modification"
        }
      ],
      "Warnings": []
    }
  ]
}

Reference:

Robs
  • 8,219
  • 6
  • 41
  • 57

1 Answers1

1

You can only modify Invoices that have the status of: 'DRAFT' or 'SUBMITTED', if it has any other status you cannot modify it, you have to delete it, and create a new one.

I believe you are probably trying to amend an 'AUTHORISED' invoice which isn't permitted via the API.

https://developer.xero.com/documentation/api/invoices

EDIT: You need to either Delete or Void an Invoice depending on Status. Here is an excerpt from my c# code using the .NET API. If the invoice is AUTHORISED you need to set it's status to VOIDED, if it's DRAFT or SUBMITTED you set it's status to DELETED

        var invoice = new Invoice();
        var api = XeroApiHelper.CoreApi();
        try
        {
            invoice = api.Invoices.Find(invoiceno);
        }
        catch (Exception ex)
        {
            // Handle the exception
        }
        if (invoice.AmountPaid == null || (invoice.AmountPaid != null && invoice.AmountPaid == 0))
        {
            if (invoice.Status == InvoiceStatus.Voided || invoice.Status == InvoiceStatus.Deleted)
            {
                //Invoice is already deleted or voided
                return false;
            }
            invoice.Status = invoice.Status == InvoiceStatus.Authorised ? InvoiceStatus.Voided : InvoiceStatus.Deleted;
            try
            {
                api.Invoices.Update(new List<Invoice> { invoice });
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return true;
        }
        // Invoice has a payment on it
        return false
sheavens
  • 685
  • 7
  • 14
  • How do I delete an invoice from Xero? (i did not think it was possible?) – Robs Sep 27 '18 at 23:33
  • @Robs I Updated my answer to show delete/void of an invoice – sheavens Sep 28 '18 at 07:53
  • For anyone else interested you can find this documented here under the heading Invoice Status Codes https://developer.xero.com/documentation/api/accounting/invoices/#get-invoices – Max Mumford Nov 06 '21 at 13:03