PHP curl with Shopify 403 Forbidden(未定义API访问的范围)



我在尝试使用 CURL 创建smart_collection时收到 403 禁止。我得到的回复是:

"错误":"未定义 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, ..."}

更新: 我发帖到不正确的网址。我已经更新了。

对于其他为此苦苦挣扎的人,在创建"smart_collection"时,请使用以下 URL:

https://___:___@___.myshopify.com//admin/smart_collections.json

最新更新