1

我正在使用 RestSharp 将发票推送到 MYOB。

RestClient myobPostInvoicesClient = new RestClient("https://api.myob.com/");                   
RestRequest myobPostInvoicesRequest = new RestRequest("au/essentials/businesses/" + business_uid + "/sale/invoices", Method.POST);
myobPostInvoicesRequest.AddHeader("Authorization", "Bearer " + access_token);
myobPostInvoicesRequest.AddHeader("x-myobapi-key", clientId);
myobPostInvoicesRequest.AddHeader("x-myobapi-version", "v0");
myobPostInvoicesRequest.AddHeader("Content-Type", "application/json");

我发送到端点的 JSON 如下

{{
  "contact": {
    "uid": "26939970"
  },
  "invoiceNumber": "IV00000000082",
  "issueDate": "2020-06-07T09:00:00",
  "dueDate": "2020-07-07T09:00:00",
  "gstInclusive": "true",
  "status": "Open",
  "lines": [
    {
      "unitOfMeasure": "Qty",
      "quantity": 5.0,
      "unitPrice": 1000.0,
      "total": 5000.0,
      "taxType": {
        "uid": "10"
      },
      "account": {
        "uid": "9"
      },
      "description": "Test Description"
    }
  ]
}}

我从 MYOB Invoice API 端点得到的响应是

"{\"errors\":[{\"field\":\"\",\"message\":\"Forbidden\",\"code\":\"403\"}]}"

访问令牌和客户端 ID 均有效,我根据以下链接遵循发票的结构

https://developer.myob.com/api/essentials-accounting/endpoints/sale/invoices/

我在请求中包含的那些以前标记为必填但 MYOB 修改了 UI 的字段。

仅供参考,我可以从 MYOB 获取联系人、帐户和税款类型,只需将 Forbidden 403 消息返回以尝试发布发票。

您能提供的任何帮助将不胜感激。

4

1 回答 1

0

如果您收到 403 Forbidden,则需要检查您用于发出 post call 的帐户的权限。

请参阅此处以了解帐户的权限

除了上面的链接

如何检查用户的访问权限

要准确了解当前用户拥有的权限,并确保他们拥有正确的权限以使您的应用程序正常运行,请向 {{company_file_uri}}/{{company_file_id}}/CurrentUser 端点发出 GET 请求。

以下响应告诉您用户对每个 url 具有哪些权限

{
    "UserAccess": [
        {
            "ResourcePath": "https://{{company_file_uri}}/{{company_file_id}}/Banking/BankAccount/",
            "Access": [
                "GET"
            ]
        },
        {
            "ResourcePath": "https://{{company_file_uri}}/{{company_file_id}}/Banking/ReceiveMoneyTxn/",
            "Access": [
                "GET",
                "POST",
                "PUT",
                "DELETE"
            ]
        },
      ...
    ]
}
于 2020-06-09T03:48:21.640 回答