我尝试通过Bexio API将文章发布到Bexio:https://docs.bexio.com/resources/article/
还有一个PHP示例:https://docs.bexio.com/samples/ 我更新了config.php中的范围,以允许读写文章。
我更新了bexioConnector.class.php,这样我就可以获取Articles(作品):
public function getArticles($urlParams = array()) {
return $this->call('article', $urlParams);
}
public function call($ressource, $urlParams = array(), $postParams = array(), $method = Curl::METHOD_GET) {
$url = $this->api_url . "/" . $this->org . "/" . $ressource;
$data = $this->curl->call($url, $urlParams, $postParams, $method, $this->getDefaultHeaders());
return json_decode($data, true);
}
所以我现在可以使用此代码来获取所有文章(作品):
$bexioProducts = $con->getArticles(array('order_by' => 'id'));
现在,我想使用POST方法创建文章。 所以我将此功能添加到了bexioConnector.class.php
public function postArticle($postParams = array(), $urlParams = array()) {
return $this->call('article', $urlParams, $postParams, Curl::METHOD_POST);
}
因此,我使用以下代码来创建产品:
$con->postArticle(array(
'intern_code' => "SKU-3214"
)
);
但这以错误结尾:
{"error_code":415,"message":"Could not parse the data."}
我已经尝试了很多,但总是收到相同的错误消息。 我可能做错了什么?
答案 0 :(得分:0)
我发现了错误。我需要先将其编码为json。 所以我更改了postArticle函数:
public function postArticle($postParams = array(), $urlParams = array()) {
$json = json_encode($postParams);
return $this->call('article', $urlParams, $json, Curl::METHOD_POST);
}