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"
 }
 ]
 }
 ]
}
Diana
5,3801 gold badge12 silver badges27 bronze badges
asked Apr 1, 2021 at 7:26

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"
 }
 ]
 }
 ]
 }
}
answered Apr 1, 2021 at 7:36
7
  • 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. Commented Apr 1, 2021 at 7:48
  • you're welcome, no problem :) 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
  • I am passing like this "options": [ { "product_sku": "test_simple_product3", "title": "Add Your Name (Max 15 Characters)", "type": "field", "sort_order": 1, "is_require": false, "price": 10, "price_type": "fixed", "sku": "Personalized", "max_characters": 15 } ] Commented Apr 1, 2021 at 9:27

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.