0

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"
                }
            ]
        }
    ]
}

1 Answer 1

1

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"
               }
            ]
         }
      ]
   }
}
8
  • what was wrong in my request body can you explain please Commented Apr 1, 2021 at 7:46
  • i think i just did :) the 'product' key should include 'custom_attributes' and 'options' and NOT be added at the same level with them. just compare my code with yours and you will see.
    – Diana
    Commented Apr 1, 2021 at 7:48
  • Ohh thanks for pointing me Commented Apr 1, 2021 at 7:53
  • you're welcome, no problem :)
    – Diana
    Commented Apr 1, 2021 at 7:58
  • when try to create field type option it won't work can you help me please. Commented Apr 1, 2021 at 9:27

Your Answer

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

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