I tried to create products in woo-commerce using API with product variations but it gives error like authentication failed.

If I remove variations from API data it works product successfully added into woo-commerce.

Below is actual code which I have used.

$data = '{
          "name": "'.$Name.'",
          "type": "simple",
          "regular_price": "'.$Price.'",
          "sku": "'.$Code.'",
          "description": "'.$Description.'",
          "categories": [
                  "id": "'.$CategoryID.'"
          "attributes": [
                "name": "Pos Id",
                "visible": true,
                "options": [
            "variations" : [
                    "visible": true,
                    "name" : "Pos Id",
                    "regular_price" : "'.$Price.'",
                    "slug" : "pos id",
                    "option" :[

        echo $url = 'http://www.xxxxxxxxx.xxx/wp-json/wc/v1/products/'.$param;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
           curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);             
            $response = curl_exec($ch);
                echo "in if";
                echo 'error:' . curl_error($ch);


Please help me with what is wrong in above code.

Read more here: How to add variations to product in woo-commerce using API


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: