Robs
Robs

Reputation: 8279

XeroAccountingApiException: 400: Invoice not of valid status for modification

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:

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:

Upvotes: 0

Views: 1425

Answers (1)

sheavens
sheavens

Reputation: 725

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

Upvotes: 1

Related Questions