XeroAccountingApiException:400:发票的有效状态无效

时间:2018-09-26 12:19:35

标签: rest xero-api

我从Xero API收到验证错误:

  

发票无效,无法修改

该消息太笼统,我们不知道为什么要得到它或如何解决它。

我尝试了不同的状态值:

  • 草稿
  • 已授权

但是我得到相同的响应:

{
  "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": []
    }
  ]
}

参考:

1 个答案:

答案 0 :(得分:1)

您只能修改状态为“ DRAFT”或“ SUBMITTED”的发票,如果它具有任何其他状态,则无法对其进行修改,您必须将其删除并创建一个新发票。

我相信您可能正在尝试修改API不允许的“授权”发票。

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

编辑:您需要根据状态删除或作废发票。这是使用.NET API的c#代码的摘录。 如果发票为AUTHORIZED,则需要将其状态设置为VOIDED;如果是DRAFT或SUBMITTED,则将其状态设置为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
相关问题