Большое спасибо за ваши решения. Я использую Shopify API вместе с методом PHP CURL POST для создания продукта. Ниже приведен код и вывод.
$products_array = array(
"product"=>array(
'title'=>'',
"title"=> "Burton Custom Freestlye 151",
"body_html"=> "<strong>Good snowboard!</strong>",
"vendor"=> "Burton",
"product_type"=> "Snowboard",
"published"=> false ,
"variants"=>array(
array(
"sku"=>"t_009",
"price"=>20.00,
"grams"=>200,
"taxable"=>false,
)
)
)
);
echo json_encode($products_array);
echo "<br />";
$url = "https://apikey:password@hostname/admin/products.json";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: 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($products_array));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec ($curl);
curl_close ($curl);
echo "<pre>";
print_r($response);
Где я использую свои учетные данные, указанные в части $ url. Я получаю следующую ошибку
{"product":{"title":"Burton Custom Freestlye 151","body_html":"Good snowboard!<\/strong>","vendor":"Burton","product_type":"Snowboard","published":false,"variants":[{"sku":"t_009","price":20,"grams":200,"taxable":false}]}}
HTTP/1.1 400 Bad Request
Server: nginx
Date: Thu, 05 Feb 2015 07:28:58 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Sorting-Hat-PodId: 0
X-Sorting-Hat-ShopId: 7628323
X-Sorting-Hat-PodId-Cached: 0
X-Sorting-Hat-ShopId-Cached: 0
Status: 400 Bad Request
X-XSS-Protection: 1; mode=block; report=/xss-report/2dfd1c1e-6c9c-4024-a9bf-f3f6b177eb17?source%5Baction%5D=create&source%5Bcontroller%5D=admin%2Fproducts&source%5Bsection%5D=admin
X-Content-Type-Options: nosniff
X-ShopId: 7628323
X-ShardId: 0
X-Shopify-Shop-Api-Call-Limit: 1/40
HTTP_X_SHOPIFY_SHOP_API_CALL_LIMIT: 1/40
X-Stats-UserId: 0
X-Stats-ApiClientId: 619259
X-Stats-ApiPermissionId: 9949639
X-Request-Id: 2dfd1c1e-6c9c-4024-a9bf-f3f6b177eb17
X-Kafka-Logged: 1
{"errors":{"product":"Required parameter missing or invalid"}}
Попробуйте изменить Accept: application/json
в Content-Type: application/json
Других решений пока нет …