0

I am new to Magento 2 and learning Rest API. I was trying to create configurable products using Rest API but I am not getting fully success.

I am able to create a configurable product and simple products. Later I am not able to connect/line simple products to configurable product. I followed Magento rest API tutorial but in my opinion, it is not cleared.

I have created a configurable product whose sku is 747682908 and simple products have sku like this 747682908-colors-size and so on.

I am now adding following thing to add options

$option = [
    "option" => [
        "attribute_id"=> "63",
        "label"=> "Size",
        "values"=> [
            ["value_index"=> 54164121323] //random int I  dont know what the hell is it.
        ]
    ],
];

This is the post URL: http://localhost/magentoTest5/rest/V1/configurable-products/747682908/options

I run the this url and later when i call this url

postData("http://localhost/magentoTest5/rest/V1/configurable-products/747682908/child", ["childSku"=>"747682908-grey-xxs"])

I get the web-5b78d12fd12 error.

[2018-11-05 16:36:52] main.CRITICAL: Report ID: webapi-5be071a475f7a; Message: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'entity_value.value' in 'field list', query was: SELECT `entity`.`sku`, `product_entity`.`entity_id` AS `product_id`, `attribute`.`attribute_code`, `entity_value`.`value` AS `value_index`, `attribute_label`.`value` AS `super_attribute_label`, IFNULL(option_value.value, default_option_value.value) AS `option_title`, `default_option_value`.`value` AS `default_title` FROM `catalog_product_super_attribute` AS `super_attribute`
 INNER JOIN `catalog_product_entity` AS `product_entity` ON product_entity.entity_id = super_attribute.product_id
 INNER JOIN `catalog_product_super_link` AS `product_link` ON product_link.parent_id = super_attribute.product_id
 INNER JOIN `eav_attribute` AS `attribute` ON attribute.attribute_id = super_attribute.attribute_id
 INNER JOIN `catalog_product_entity` AS `entity` ON entity.entity_id = product_link.product_id
 INNER JOIN `catalog_product_entity` AS `entity_value` ON entity_value.attribute_id = super_attribute.attribute_id AND entity_value.store_id = 0 AND entity_value.entity_id = entity.entity_id
 LEFT JOIN `catalog_product_super_attribute_label` AS `attribute_label` ON super_attribute.product_super_attribute_id = attribute_label.product_super_attribute_id AND attribute_label.store_id = 0
 LEFT JOIN `eav_attribute_option` AS `attribute_option` ON attribute_option.option_id = entity_value.value
 LEFT JOIN `eav_attribute_option_value` AS `option_value` ON option_value.option_id = entity_value.value AND option_value.store_id = 1
 LEFT JOIN `eav_attribute_option_value` AS `default_option_value` ON default_option_value.option_id = entity_value.value AND default_option_value.store_id = 0 WHERE (super_attribute.product_id = 6) AND (attribute.attribute_id = '') ORDER BY `attribute_option`.`sort_order` ASC
 {"exception":"[object] (Exception(code: 42): Report ID: webapi-5be071a475f7a; Message: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'entity_value.value' in 'field list', query was: SELECT `entity`.`sku`, `product_entity`.`entity_id` AS `product_id`, `attribute`.`attribute_code`, `entity_value`.`value` AS `value_index`, `attribute_label`.`value` AS `super_attribute_label`, IFNULL(option_value.value, default_option_value.value) AS `option_title`, `default_option_value`.`value` AS `default_title` FROM `catalog_product_super_attribute` AS `super_attribute`
 INNER JOIN `catalog_product_entity` AS `product_entity` ON product_entity.entity_id = super_attribute.product_id
 INNER JOIN `catalog_product_super_link` AS `product_link` ON product_link.parent_id = super_attribute.product_id
 INNER JOIN `eav_attribute` AS `attribute` ON attribute.attribute_id = super_attribute.attribute_id
 INNER JOIN `catalog_product_entity` AS `entity` ON entity.entity_id = product_link.product_id
 INNER JOIN `catalog_product_entity` AS `entity_value` ON entity_value.attribute_id = super_attribute.attribute_id AND entity_value.store_id = 0 AND entity_value.entity_id = entity.entity_id
 LEFT JOIN `catalog_product_super_attribute_label` AS `attribute_label` ON super_attribute.product_super_attribute_id = attribute_label.product_super_attribute_id AND attribute_label.store_id = 0
 LEFT JOIN `eav_attribute_option` AS `attribute_option` ON attribute_option.option_id = entity_value.value
 LEFT JOIN `eav_attribute_option_value` AS `option_value` ON option_value.option_id = entity_value.value AND option_value.store_id = 1
 LEFT JOIN `eav_attribute_option_value` AS `default_option_value` ON default_option_value.option_id = entity_value.value AND default_option_value.store_id = 0 WHERE (super_attribute.product_id = 6) AND (attribute.attribute_id = '') ORDER BY `attribute_option`.`sort_order` ASC
 at /var/www/html/magentoTest5/vendor/magento/framework/Webapi/ErrorProcessor.php:205, Zend_Db_Statement_Exception(code: 42): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'entity_value.value' in 'field list', query was: SELECT `entity`.`sku`, `product_entity`.`entity_id` AS `product_id`, `attribute`.`attribute_code`, `entity_value`.`value` AS `value_index`, `attribute_label`.`value` AS `super_attribute_label`, IFNULL(option_value.value, default_option_value.value) AS `option_title`, `default_option_value`.`value` AS `default_title` FROM `catalog_product_super_attribute` AS `super_attribute`
 INNER JOIN `catalog_product_entity` AS `product_entity` ON product_entity.entity_id = super_attribute.product_id
 INNER JOIN `catalog_product_super_link` AS `product_link` ON product_link.parent_id = super_attribute.product_id
 INNER JOIN `eav_attribute` AS `attribute` ON attribute.attribute_id = super_attribute.attribute_id
 INNER JOIN `catalog_product_entity` AS `entity` ON entity.entity_id = product_link.product_id
 INNER JOIN `catalog_product_entity` AS `entity_value` ON entity_value.attribute_id = super_attribute.attribute_id AND entity_value.store_id = 0 AND entity_value.entity_id = entity.entity_id
 LEFT JOIN `catalog_product_super_attribute_label` AS `attribute_label` ON super_attribute.product_super_attribute_id = attribute_label.product_super_attribute_id AND attribute_label.store_id = 0
 LEFT JOIN `eav_attribute_option` AS `attribute_option` ON attribute_option.option_id = entity_value.value
 LEFT JOIN `eav_attribute_option_value` AS `option_value` ON option_value.option_id = entity_value.value AND option_value.store_id = 1
 LEFT JOIN `eav_attribute_option_value` AS `default_option_value` ON default_option_value.option_id = entity_value.value AND default_option_value.store_id = 0 WHERE (super_attribute.product_id = 6) AND (attribute.attribute_id = '') ORDER BY `attribute_option`.`sort_order` ASC
 at /var/www/html/magentoTest5/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:235, PDOException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column 'entity_value.value' in 'field list' at /var/www/html/magentoTest5/vendor/magento/zendframework1/library/Zend/Db/Statement/Pdo.php:228)"

Please, anybody, help me to solve the issue.

In short: how do I add/link simple products to the configurable products and what is the value_index? I googled it also but Didn't find any solution.

Please help me. Thanks in advanced for any help.

0

My guess would be that the variable $option you're creating doesn't follow the guidelines you find in the Magento DevDoc.

Payload should be

{
  "option": {
    "attribute_id": "141",
    "label": "Size",
    "position": 0,
    "is_use_default": true,
    "values": [ // -> this is an array
      { // -> this is an object within an array
        "value_index": 9 
      }
    ]
  }
}

What you're creating is:

$option = [
    "option" => [
        "attribute_id"=> "63",
        "label"=> "Size",
        "values"=> [ // -> this is an object
            [ //-> this is an object within an object
              "value_index"=> 54164121323 
            ] 
        ]
    ],
];

What is the response you get from http://localhost/magentoTest5/rest/V1/configurable-products/747682908/options? 200?

EDIT:

Try this instead:

$option = [
    "option" => [
        "attribute_id"=> "63",
        "label"=> "Size",
        "values"=> array(
            [
              "value_index"=> 100
            ] 
        )
    ],
];
  • Thank very much for answering, the values I created in $option variable are only those are not optionl. I get this response body {"message":"Internal Error. Details are available in Magento log file. Report ID: webapi-5be07a11a12c9"} – Phoenix404 Nov 5 '18 at 17:13
  • Yes, I see that are only the ones that are not optional. But the "values" key (which you used) is supposed to be an array, not an object. – Luca D.R. Nov 5 '18 at 17:14
  • I've edited the answer with a possible solution. – Luca D.R. Nov 5 '18 at 17:18
  • ok thanks but what does mean that value_index ? – Phoenix404 Nov 5 '18 at 17:19
  • I tried your solution but didn't worked :( – Phoenix404 Nov 5 '18 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.