问题描述
我正在尝试使用确切的在线API,我的Web应用程序可以与该API连接并创建“帐户”,“项目”和所有其他内容。
但是现在,在我的Web应用程序内部,我需要那些Accounts and Items etcetera,我已经完成了选择所有Items并将其导入到数据库的操作,但是我找不到 SalesPrice 一个商品,只有“ CostPriceNew”和“ CostPriceStandard”!
经过一段时间的搜索,我发现在该类中还有一个名为 ItemDetailsByID 的类,我发现了 SalesPrice
起初我得到一个错误:Fatal error: Uncaught TypeError: Argument 1 passed to Picqer\Financials\Exact\ItemDetailsByID::get() must be of the type array,string given
这是我使用的代码: `
//Retrieve items
$items = new \Picqer\Financials\Exact\Item($connection);
$result = $items->get();
foreach ($result as $item) {
try {
$ItemDetails = new \Picqer\Financials\Exact\ItemDetailsByID($connection);
$result1 = $ItemDetails->get($item->ID);
foreach ($result1 as $ItemDetail) {
var_dump($ItemDetail);
}
} catch (\Exception $e) {
echo json_encode(array(get_class($e) . ' : ' . $e->getMessage()));
}
}
`
从确切的在线阅读文档后,我仍然没有设法使用此类。.现在,我收到此错误:["Picqer\\Financials\\Exact\\ApiException : Error 400: Bad Request - Error in query Syntax."]
出现第一个错误后,我更改了代码$result1 = $ItemDetails->get($item->ID);
进入
$result1 = $ItemDetails->get(["eq guid" => "'$item->ID'"]);
我尝试了多个数组键,例如:'eq guid','Edm.Guid','guid','id',但我仍然错误。
我希望有人能帮助我或为我指明正确的方向。
解决方法
您的问题不是很清楚,在您添加更多信息之前,我会尝试为您提供一般性建议。
记录http协议并与文档进行比较,如果您没有客户端日志,则可以将请求发送到httpbin.org(请谨慎使用第三方服务来密码和其他个人盗版行为),就像https://httpbin.org/get?itemId=guid'00000000-0000-0000-0000-000000000000'&$select=Code,SalesPrice。
它将打印请求信息,这有助于调试
{
"args": {
"$select": "Code,SalesPrice","itemId": "guid'00000000-0000-0000-0000-000000000000'"
},"headers": {
"Accept": "*/*","Accept-Encoding": "gzip,deflate,br","Cache-Control": "no-cache","Host": "httpbin.org","User-Agent": "PostmanRuntime/7.26.5",},"origin": "a.b.c.d","url": "https://httpbin.org/get?itemId=guid'00000000-0000-0000-0000-000000000000'&$select=Code,SalesPrice"
}
,
您不想列出所有商品的价格,因此不应使用 get,而应使用 find。由于只得到一个结果,之后就可以直接使用返回的对象了:
$ItemDetails = new \Picqer\Financials\Exact\ItemDetailsByID($connection);
$result1 = $ItemDetails->find($item->ID);
var_dump($result1->SalesPrice);