1

While running below code to add configruable product,I get unable to save products.

try {
     $url = 'http://ddddd.com/index.php';
      $api_username = 'admin';
      $api_password = 'admin1234$';
    $userData = array("username" => $api_username, "password" => $api_password);


    $ch = curl_init($url."/rest/V1/integration/admin/token");
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($userData));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Content-Lenght: " . strlen(json_encode($userData))));

    $token = curl_exec($ch);
    $product_data= '{
      "product":{
        "sku":"KudosConfigssss",
        "name":"Kudos Configurablesssss",
        "price":110.0000,
        "status":4,
        "type_id":"configurable",
        "attribute_set_id":4,
        "weight":1,
        "extension_attributes":{
          "stock_item":{
            "qty":10,
            "is_in_stock":true
          },

          "configurable_product_options":[
            {
              "attribute_id":"90",
               "label":"color",
              "values":[
                {
                  "value_index":54
                },
                {
                  "value_index":109
                }
              ]
            },
            {
              "attribute_id":"159",
               "label":"size",
              "values":[
                {
                  "value_index":15
                },
                {
                  "value_index":16
                }
              ]
            }
          ]
        }
      }
    }';


     $ch = curl_init($url."/rest/V1/products");
     curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POSTFIELDS,$product_data);
     curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token)));

     $result = curl_exec($ch);
     }catch(Exception $e){

           echo $e->getMessage();

     }

     /****** Show results ****/ 
    var_dump($result);
1
  • Check you are on developer mode or production mode. Nov 5, 2018 at 11:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.