首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Sage记账接口UnexpectedError

Sage记账接口UnexpectedError
EN

Stack Overflow用户
提问于 2019-06-13 19:32:01
回答 1查看 177关注 0票数 1

我正在尝试通过Sage Accounting API调用创建一个销售发票(它的文档可以在这里找到:https://developer.sage.com/api/accounting/api/)

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

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

代码语言:javascript
复制
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;
}

如何调用此方法:

代码语言:javascript
复制
$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文档,这应该可以工作,但我仍然收到这个错误:

代码语言:javascript
复制
[$severity] => error
[$dataCode] => UnexpectedError
[$message] => An unexpected error occurred.
[$source] => 

如果有人有使用Sage Accounting API的经验,我非常希望知道我做错了什么。

EN

回答 1

Stack Overflow用户

发布于 2019-06-13 23:06:56

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

代码语言:javascript
复制
{
  "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“税率的例子更新这个答案。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56579506

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档