【问题标题】:Sage Accounting API UnexpectedErrorSage Accounting API UnexpectedError
【发布时间】:2019-10-27 23:44:48
【问题描述】:

我正在尝试通过 Sage Accounting API 调用创建销售发票(其文档可在此处找到:https://developer.sage.com/api/accounting/api/

为了使我的代码更清晰,我创建了一个类来帮助我进行相应的调用。

这是我用来进行这些调用的方法:

public function postRequest()
{
    $url = $this->baseEndpoint . $this->request;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    if (isset($this->params)) {
        curl_setopt($ch, CURLOPT_POSTFIELDS, $this->params);
    }

    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        "Authorization: Bearer $this->token",
        "Host: api.accounting.sage.com",
        "Content-Type: application/json"
    ));
    $response = json_decode(curl_exec($ch), true);
    curl_close($ch);
    return $response;
}

我如何称呼这个方法:

$params = array(
"sales_invoice" => array(
    "contact_id" => "485fdfe0be154f9c9af44351de16e5be",
    "date" => "2019-06-13",
    "invoice_lines" => array(
        array(
            "description" => "description",
            "ledger_account_id" => "f04157c90ff0496ab3a22f2558e46010",
            "unit_price" => 10   ,
            "quantity" => 1,
            "tax_rate_id" => "ES_RE_STANDARD",
            "tax_rate" => 0.1
        )
    )
)
);

$params = json_encode($params);
$request = "v3.1/sales_invoices";
$sageRequest = new SageRequest($token, $request, $params);
$sageRequest->postRequest();

根据 API 文档,应该可以,但我仍然收到此错误:

[$severity] => error
[$dataCode] => UnexpectedError
[$message] => An unexpected error occurred.
[$source] => 

如果有人对 Sage Accounting API 有一定的经验,我会非常感激知道我做错了什么。

【问题讨论】:

    标签: php sage-one


    【解决方案1】:

    这个例子适用于我的西班牙企业:

    {
      "sales_invoice": {
        "contact_id": "22b609fba11642238f2ecd0f5fe3e0b5",
        "date": "2019-06-12",
        "invoice_lines": [
          {
            "description": "Description",
            "ledger_account_id": "829739738de811e996c90122ae3d08ca",
            "quantity": 1,
            "unit_price": 100,
            "tax_rate_id": "ES_STANDARD"
          }
        ],
        "main_address": {
          "city": "Madrid"
        }
      }
    }
    

    确保您的联系人列在联系人端点中。使用GET https://api.accounting.sage.com/v3.1/ledger_accounts?visible_in=sales 获取销售对象的所有有效分类帐帐户的列表。

    我看到您的问题使用ES_RE_STANDARD 作为税率。我将很快用“recargo de equivalencia”税率的例子来更新这个答案。

    【讨论】:

    • 您好,谢谢您的回答。我已经使用了您的示例(当然,使用了我的一个联系人和分类帐帐户)并且收到错误消息: Entschuldigung - Zurzeit besteht ein technisches Problem。我之前偶然发现了这个错误,但看起来这是一个技术问题。我觉得很难相信……
    • 此错误可能来自发布无效的 JSON。你能确保你发布的是有效的 JSON 吗?这绝对是糟糕的错误处理,很快就会修复。
    • 是的,有效。
    • 您能否将包含一些详细信息的请求发送至 sageonedevelopers@sage.com,包括 x-request-id 响应标头?这将有助于我们查询日志以更好地帮助您。
    • 是的,我刚刚给你发了邮件。
    猜你喜欢
    • 1970-01-01
    • 2016-06-22
    • 2015-09-19
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    • 2021-01-23
    • 2020-08-24
    • 2013-06-07
    相关资源
    最近更新 更多