尝试使用CURL创建smart_collection时,我收到403 Forbidden。我得到的答复是:
“错误”:“未定义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, ..."}
答案 0 :(得分:0)
更新: 我张贴到错误的URL。此后我已经更新。
对于其他为此苦苦挣扎的人,在创建“ smart_collection”时,请使用以下网址:
https://___:___@___.myshopify.com//admin/smart_collections.json