How can I update the custom attributes such as description? The following code properly update price and product name, but not custom attributes (unchanged). The new product is created properly with custom attributes, the problem is while updating.
-
Hi guys, in your case,I think you need do again: php bin/magento upgrade– MrTo-KaneCommented Dec 25, 2016 at 17:56
-
Hi guys, I think you give us the code or config of attribute for custom_attributes. To we check again.– MrTo-KaneCommented Dec 26, 2016 at 2:18
-
Have you check any answer? need your comments.– Chirag PrajapatiCommented Dec 26, 2016 at 9:05
Add a comment
|
2 Answers
To create product, we can use:
- POST: /V1/products
For updating:
- PUT: /V1/products/{sku}
In your case, your code should be:
$productData = [
'attribute_set_id' => 4,
"type_id": "simple",
"sku": "test-SKU",
"name": "Test",
"price": 100,
"status": 1,
'custom_attributes' => [
['attribute_code' => 'description', 'value' => 'Test Description' ],
['attribute_code' => 'short_description', 'value' => 'Test Short Description' ],
]
];
The JSON body:
{
"product": {
"sku": "test-SKU",
"name": "Test",
"attribute_set_id": 4,
"price": 100,
"status": 1,
"custom_attributes": [
{
"attribute_code": "description",
"value": "Test Description"
},
{
"attribute_code": "short_description",
"value": "Test Short Description"
}
]
}
}
There is an answer here: https://magento.stackexchange.com/a/135607/33057
-
Hi , @Khoa you need to format array to json string, because he used REST and by REST tool. Commented Dec 25, 2016 at 17:54
-
-
@Khoa TruongDinh How to add selected attributes label in product rest API. Like ['attribute_code' => 'description', 'value' => 'Test Description', 'label' => 'Description' ], Commented Sep 5, 2019 at 5:50
-
-
@KhoaTruongDinh How to pass label in /V1/products/{sku} 'attribute_code' => 'color', 'value' => '54', 'label' => 'Blue' Let me know if you have idea. Your help would be appreciated. Commented Sep 5, 2019 at 13:33
Try to pass your custom attributes within array like:
'custom_attributes' => array(
'0' => array(
'attribute_code' => 'my_custom_attribute_code',
'value' => 'my_custom_attribute_value'
)
...
)
-
How to pass label in /V1/products/{sku} 'attribute_code' => 'color', 'value' => '54', 'label' => 'Blue' Let me know if you have idea. Your help would be appreciated. Commented Sep 5, 2019 at 13:31
-