Multiple Variants and Option - Error "name cant be blank"

Highlighted
New Member
6 0 0

I'm trying to create a product with multiple variants and option. I used the example json on the shopify api documentation. But its giving me an error. Seems the example is wrong?

 

require_once("inc/functions.php");
$shop = "abc";
setGlobalVariables( $shop) ;


$product_json = '{
  "product": {
    "title": "Burton Custom Freestyle 151",
    "body_html": "<strong>Good snowboard!</strong>",
    "vendor": "Burton",
    "product_type": "Snowboard",
    "variants": [
      {
        "option1": "Blue",
        "option2": "155"
      },
      {
        "option1": "Black",
        "option2": "159"
      }
    ],
    "options": [
      {
        "name": "Color",
        "values": [
          "Blue",
          "Black"
        ]
      },
      {
        "name": "Size",
        "values": [
          "155",
          "159"
        ]
      }
    ]
  }
}';

$products_array=json_decode($product_json, true);

$modified_product = shopify_call($token, $shop, "/admin/api/".$shopifyVer."/products.json",$products_array,'POST');
$modified_product_response = $modified_product['response'];
 


echo "<pre>";
print_r($modified_product_response);
echo "</pre>";

echo "Successfully Inserted.";

This is the code i used. Hope someone can help me with this. Thanks!

0 Likes
Highlighted
Shopify Staff
Shopify Staff
387 72 54

Hey @raff25c 

 

The code from the docs should work fine. If you run this in Insomnia / Postman first to test you will see this. Can you replicate in an API client? 

Vix | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 


0 Likes