【发布时间】:2019-05-24 15:38:54
【问题描述】:
我在尝试使用 CURL 创建 smart_collection 时收到 403 Forbidden。我得到的回应是:
"errors":"未定义 API 访问范围:集合。
我在以前的私人 Shopify 应用程序中使用相同的 CURL 代码块成功创建产品。我还查看了 Shopify 上私有应用程序的所有权限,并且可以确认它们已设置为最高。
我的问题是,为了成功将 smart_collection 发布到 Shopify,还需要什么。发帖时如何定义范围?
<?php
//this gets the collection name from the URL
if(isset($_GET['id'])){
$collection_name = $_GET['id'];
}
$collection_array = array(
"smart_collection"=>array(
"title"=> $collection_name,
"rules"=>array(
array(
"column" => "tag",
"relation" => "equals",
"condition" => $collection_name
),
array(
"column" => "variant_inventory",
"relation" => "greater_than",
"condition" => 0
)
)
)
);
echo json_encode($collection_array);
echo "<br />";
$url ="https://apikey:password@mystore.myshopify.com
/admin/smart_collections.json";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:
application/json'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, 0);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS,
json_encode($collection_array));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec ($curl);
curl_close ($curl);
echo "<pre>";
print_r($response);
预期结果: 应根据 $colletion_array 在 Shopify 上创建 smart_collection,例如:
{
"smart_collection": {
"title": "3DLightFX",
"rules": [
{
"column": "tag",
"relation": "equals",
"condition": "3DLightFX"
},
{
"column": "variant_inventory",
"relation": "greater_than",
"condition": 0
}
]
}
}
实际结果: 我收到了
403 forbidden,回复是:
{"errors":"Scope undefined for API access: collections. Valid scopes: admin_notifications, ..."}
【问题讨论】: