正确的 shopify api 产品创建

Proper shopify api product create

我正在尝试使用 shopify api 创建产品,但产品未设置且我没有收到任何错误。 print_r($server_output); 什么都不显示,所以我看不出哪里错了。卷曲也被启用。下面是我使用的代码。
当我 print_r($products); 它显示数组应该如何。我做错了什么吗?

$name='test product 555';
$group=36;
$quantity=20;
$price='20.95';

$url = 'https://my_key_and_pass/admin/products.json';
$type = 'POST';
$product = array('title' => utf8_encode($name),
        'body_html' => utf8_encode($name),
        'product_type'=> $group,
        'variants' => array(
        array('price' => $price,
        'inventory_quantity'=> $quantity,
        'inventory_management' => 'shopify'
        )
        )
        );

$ch = curl_init($url);
$data_string = json_encode(array('product'=>$product));
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Content-Type: application/json',
        'Content-Length: ' . strlen($data_string))
        );
$server_output = curl_exec ($ch);
print_r($server_output);
curl_close ($ch);

我对 PHP/curl 不太熟悉,但您可能遗漏了 post 字段数:

curl_setopt($ch, CURLOPT_POST, count($data_string));

curl_setopt($ch, CURLOPT_POST, 1);

因为你只有一个产品。

你试过Postman这样的应用吗?在那里有用吗?

问题是主机没有启用 SSL,所以此代码解决了它:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);