我一直在尝试使用 Shopify API 添加新的自定义集合。但不断收到错误标题不能为空。
虽然标题已在 POST 字段中设置
我的代码如下:
$url = 'https://APIKEY:APIPASS@DOMAIN.myshopify.com/admin/custom_collections.json';
$collection = array
(
"custom_collection" => array( 'title' => 'Made In the USA' )
);
// $payload = json_encode($collection);
$payload = '{
"custom_collection": {
"title": "IPods",
"collects": [
{
"product_id": 99395358
}
]
}
}';
$ch = curl_init( $url );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'HAC');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $payload);
$return = curl_exec( $ch );
curl_close( $ch );
我得到回应
{"errors":{"title":["can't be blank"]}}