You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Xero API创建含负金额行项目发票时折扣率0.00无效报错

解决Xero API创建含负金额行项目发票的折扣率验证错误

可以通过Xero API实现创建含负金额行项目的发票,你遇到的BadRequest错误是因为负金额行项目的折扣字段设置触发了API的严格验证规则——即使折扣值为0,API也会判定无效,而Xero UI会自动处理这类字段,所以不会报错。

解决方法

对负金额的行项目,直接移除DiscountRate和DiscountAmount字段(不要设置为0),正金额行项目的折扣字段可正常保留(无需折扣时也可移除)。修改后的请求示例如下:

{
    "AmountDue": 1.0,
    "AmountPaid": 0.0,
    "Contact": {
        "ContactID": "080d6f7d-db12-4a35-ae52-de5a4e815b4d"
    },
    "CurrencyCode": "CAD",
    "CurrencyRate": 0.0,
    "Date": "2024-05-02T15:22:44",
    "LineAmountTypes": "Exclusive",
    "LineItems": [
        {
            "AccountCode": "200",
            "Description": "item2",
            "DiscountAmount": 0.0,
            "DiscountRate": "0.00000",
            "ItemCode": "item2",
            "LineAmount": 10.0,
            "Quantity": 1.0,
            "TaxAmount": 0.0,
            "UnitAmount": 10.0
        },
        {
            "AccountCode": "200",
            "Description": "item3",
            "ItemCode": "item3",
            "LineAmount": -9.0,
            "Quantity": 1.0,
            "TaxAmount": 0.0,
            "UnitAmount": -9.0
        }
    ],
    "SentToContact": false,
    "Status": "DRAFT",
    "SubTotal": 1.0,
    "Total": 1.0,
    "TotalDiscount": 0.0,
    "TotalTax": 0.0,
    "Type": "ACCREC"
}

修改后提交请求,即可成功创建包含负金额行项目的草稿发票,效果与Xero UI操作一致。

内容的提问来源于stack exchange,提问作者Anton Serhieiev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 17:27:44