我正在尝试通过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有一定的经验,我将不胜感激知道自己做错了什么。
答案 0 :(得分:0)
此示例适用于我在西班牙开展的业务:
{
"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”税率为例,很快更新此答案。