无法通过API 422错误将发票过帐到Sage One

时间:2019-04-15 06:37:27

标签: vb.net api sage-one

我能够通过SAGE ONE API进行身份验证,还能够从API中检索数据,但是我现在尝试发布简单的发票,但是始终会收到422错误。有什么明显的我想念的东西吗?

我已经仔细检查了JSON结构和我提供的值,它们都是有效的。不知道我在这里做错了吗!

我的JSON包如下所示

{"contact_id":"66b76fa19edc11e797950a57719b2edb",
"date":"2019-04-13",
"invoice_lines":[{"description":"Test Description",
"ledger_account_id":"0367afd89ece11e797950a57719b2edb","quantity":1,"unit_price":100}]}

code 

Dim http As HttpWebRequest = WebRequest.Create(New Uri("https://api.columbus.sage.com/uki/sageone/accounts/v3/sales_invoices"))
            http.Method = "POST"
            http.ContentType = "application/json"
            http.Accept = "application/json"
            http.Headers.Add("X-Site", "mysite")
            http.Headers.Add("ocp-apim-subscription-key", "mykey")
            http.Headers.Add("Authorization", "Bearer " mytoken)

            Dim data = Encoding.UTF8.GetBytes(json)
            http.ContentLength = data.Length

            Dim stream = http.GetRequestStream()
            stream.Write(data, 0, data.Length)
            stream.Close()

            Dim response = http.GetResponse().GetResponseStream()

1 个答案:

答案 0 :(得分:1)

此POST正文为我工作(具有不同的ID):

{
  "sales_invoice": {
    "contact_id": "66b76fa19edc11e797950a57719b2edb",
    "date": "2019-04-13",
    "main_address": { "address_line_1": "42 Test Street" },
    "invoice_lines": [
      {
        "description": "Test Description",
        "ledger_account_id": "0367afd89ece11e797950a57719b2edb",
        "quantity": 1,
        "unit_price": 100,
        "tax_rate_id": "GB_NO_TAX"
      }
    ]
  }
}

您需要使用密钥包装JSON结构,该密钥是资源的名称(在这种情况下为"sales_invoice")。

您还需要指定一个主要地址,以及每个订单项的税率ID。

要确保您的销售发票有一个有效的分类帐帐户,请获取具有以下内容的可能帐户的列表:

GET /ledger_accounts?visible_in=sales