Shopify调用inventory_levels/set接口报inventory_item_id参数无效如何解决
错误含义
该报错表示Shopify接口没有从你提交的请求数据中解析到符合要求的inventory_item_id参数,并非你传入的变量值本身有问题,而是请求体的封装结构不符合接口规范。
修复方法
你代码的核心错误是给请求参数额外套了一层inventory_levels/set的父级键,这个字段是接口路径的一部分,不需要放到请求体里。直接把三个参数放在JSON根层级即可,修正后的代码如下:
$url = "https://app:pwd@url.myshopify.com/admin/api/2021-10/inventory_levels/set.json"; $data_json=json_encode( array( "location_id" => $idlocation, "inventory_item_id" => $invitem, "available" => $qty ), ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Content-Length: ' . strlen($data_json))); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); var_dump($response);
其他校验点
- 确认你使用的API凭证已开通
write_inventory权限,库存修改类接口需要该权限才能正常调用 - 若调整后仍有报错,可直接打印
$data_json检查参数格式,确认inventory_item_id是数字类型而非字符串类型
内容的提问来源于stack exchange,提问作者Luca Calabrese
相关产品推荐
相关产品推荐

