Debitoor API返回400错误请求

时间:2018-05-06 16:53:42

标签: json rest api post jsonschema

我想通过PHP脚本创建发票。但在我能够编程之前,我想了解Debitoor的API。

要创建发票,您必须先创建草稿发票。你可以在这里找到:/api/sales/draftinvoices/v3

我已将所有请求的参数设置为使用/ api / sales / draftinvoices / v3函数,但是,我总是得到400 Bad Request响应。原因是架构。

你能告诉我我的失败在哪里吗? 我猜这是"线" ...但我会说这一切都是正确的......

这是我的要求: enter image description here

以文字形式提出要求:

{
  "date": "2018-05-06",
  "dueDate": "2018-05-13",
  "notes": "Diese Rechnung ist vom Backend erstellt worden.",
  "customerName": "Max Mustermann",
  "customerAddress": "Mustermann Stra\u00dfe",
  "customerCountry": "DE",
  "currency": "EUR",
  "languageCode": "de-DE",
  "recargoTaxEnabled": false,
  "sent": false,
  "viewed": false,
  "displayAsPaid": false,
  "lines": {
    "taxEnabled": "false",
    "description": "Leistungszeitraum 06.04.2018 - 05.05.2018",
    "taxRate": "1.19",
    "productOrService": "product"
  }
}

这是我回复的回复: enter image description here

正如文字:

{
  "message": "Error validating against schema",
  "id": "9905636b-fb65-41a0-8d25-4aa096d5347d",
  "code": "schema",
  "errors": [
    {
      "message": "is the wrong type",
      "value": {
        "taxEnabled": "false",
        "description": "Leistungszeitraum 06.04.2018 - 05.05.2018",
        "taxRate": "1.19",
        "productOrService": "product"
      },
      "type": "array",
      "property": "lines"
    }
  ],
  "body": {
    "date": "2018-05-06",
    "dueDate": "2018-05-13",
    "notes": "Diese Rechnung ist vom Backend erstellt worden.",
    "customerName": "Max Mustermann",
    "customerAddress": "Mustermann Stra\u00dfe",
    "customerCountry": "DE",
    "currency": "EUR",
    "languageCode": "de-DE",
    "recargoTaxEnabled": false,
    "sent": false,
    "viewed": false,
    "displayAsPaid": false,
    "lines": {
      "taxEnabled": "false",
      "description": "Leistungszeitraum 06.04.2018 - 05.05.2018",
      "taxRate": "1.19",
      "productOrService": "product"
    }
  }
}

亲切的问候,谢谢!

1 个答案:

答案 0 :(得分:1)

感谢您使用Debitoor API

你是对的。你的问题在于线条。行应该是一个数组。您只发送了一个对象。

另一个问题是您提供了taxEnabled: falsetaxRate: 1.19。如果您将taxEnabled设为false,则应将taxRate设置为0.请记住,taxRate应介于0到100之间,最多为两位小数

您的请求应该是这样的:

{ "lines": [ { "taxEnabled": false, "description": "Leistungszeitraum 06.04.2018 - 05.05.2018", "taxRate": 0, "quantity": 1, "unitNetPrice": 1, "productOrService": "product" } ]

致以最诚挚的问候,

的Carsten

移动开发者@ Debitoor