Question

I am trying to create simple product with custom option using rest api but custom option is not saving with product endpoint rest/V1/products. anything missing here

Here is my request body

    {
    "product": {
        "sku": "test_simple_product3",
        "name": "Test Simple Product",
        "attribute_set_id": 4,
        "price": 25,
        "status": 1,
        "visibility": 1,
        "type_id": "simple",
        "weight": "0.5"
    },
    "custom_attributes": [
        
        {
            "attribute_code": "has_options",
            "value": 1
        },
        {
            "attribute_code": "required_options",
            "value": 1
        }
    ],
    "options": [
        {
            "product_sku": "test_simple_product3",
            "title": "Scelta",
            "type": "checkbox",
            "sort_order": null,
            "is_require": true,
            "price_type": null,
            "values": [
                {
                    "title": "A3",
                    "sort_order": 1,
                    "price": 7.35,
                    "price_type": "fixed",
                    "sku": "A3"
                },
                {
                    "title": "A4",
                    "sort_order": 1,
                    "price": 9.45,
                    "price_type": "fixed",
                    "sku": "A4"
                }
            ]
        }
    ]
}
Was it helpful?

Solution

As per the documentation in Redoc https://magento.redoc.ly/2.3.6-admin/tag/products#operation/catalogProductRepositoryV1SavePost, the main key 'product' holds all the product information, including the attribute values and the options definition.


Your payload should look like this

{
   "product":{
      "sku":"test_simple_product3",
      "name":"Test Simple Product",
      "attribute_set_id":4,
      "price":25,
      "status":1,
      "visibility":1,
      "type_id":"simple",
      "weight":"0.5",
      "custom_attributes":[
         {
            "attribute_code":"has_options",
            "value":1
         },
         {
            "attribute_code":"required_options",
            "value":1
         }
      ],
      "options":[
         {
            "product_sku":"test_simple_product3",
            "title":"Scelta",
            "type":"checkbox",
            "sort_order":null,
            "is_require":true,
            "price_type":null,
            "values":[
               {
                  "title":"A3",
                  "sort_order":1,
                  "price":7.35,
                  "price_type":"fixed",
                  "sku":"A3"
               },
               {
                  "title":"A4",
                  "sort_order":1,
                  "price":9.45,
                  "price_type":"fixed",
                  "sku":"A4"
               }
            ]
         }
      ]
   }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top