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
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"
}
]
}
]
}
}
-
what was wrong in my request body can you explain pleasemagento stacker– magento stacker2021年04月01日 07:46:37 +00:00Commented 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– Diana2021年04月01日 07:48:21 +00:00Commented Apr 1, 2021 at 7:48
-
you're welcome, no problem :)Diana– Diana2021年04月01日 07:58:43 +00:00Commented Apr 1, 2021 at 7:58
-
when try to create
fieldtype option it won't work can you help me please.magento stacker– magento stacker2021年04月01日 09:27:12 +00:00Commented 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 } ]magento stacker– magento stacker2021年04月01日 09:27:48 +00:00Commented Apr 1, 2021 at 9:27