I am attempting to set custom attributes when creating a new product via the REST API. The products have a required attribute hpUuid
. This is part of my JSON file to create the new product:
{
"product": {
"sku": "12345",
... Quite a few fields here ...
"custom_attributes": [
{
"attribute_code": "hpUuid",
"value": "123"
}
],
}
}
When submitting, the REST API returns this error:
{"message":"The \"hpUuid\" attribute value is empty. Set the attribute and try again."}
The fine docs suggest that the format is correct, but why can it not read the value?
EDIT: More information
I have tried two similar request bodies, based on different examples that I have found. One based on the fine manual is here:
{
"product": {
"name": "My Fine Product",
"sku": "123",
"attribute_set_id": 4,
"status": 1,
"visibility": 4,
"type_id": "configurable",
"extension_attributes": {
"category_links": [
{
"position": 0,
"category_id": "2"
}
]
},
"custom_attributes": [
{
"attribute_code": "hpUuid",
"value": "52"
}
]
}
}
And another based on an accepted Stack Overflow answer is here:
{
"product": {
"sku": "sku_from_rest",
"name": "My Fine Product",
"attribute_set_id": "4",
"status": 1,
"visibility": 4,
"type_id": "virtual",
"weight": 0,
"extension_attributes": {
"stock_item": {
"stock_id": 1,
"qty": 20,
"is_in_stock": true,
"is_qty_decimal": false,
"use_config_min_qty": true,
"min_qty": 0,
"use_config_min_sale_qty": 0,
"min_sale_qty": 0,
"use_config_max_sale_qty": true,
"max_sale_qty": 0,
"use_config_backorders": false,
"backorders": 0,
"use_config_notify_stock_qty": true,
"notify_stock_qty": 20,
"use_config_qty_increments": false,
"qty_increments": 0,
"use_config_enable_qty_inc": false,
"enable_qty_increments": false,
"use_config_manage_stock": true,
"manage_stock": true,
"low_stock_date": "string",
"is_decimal_divided": true,
"stock_status_changed_auto": 0,
"extension_attributes": {}
}
},
"custom_attributes": [
{
"attribute_code": "hpUuid",
"value": "123"
}
]
}
}
I have ensured that the attribute_set_id
value of 4
is correct for the default attribute set. I have addionally added an attribute set number 9
which is a clone of the Default set. However, when I use the attribute_set_id
value of 9
the product is created without an hpUuid
, as if the value that I submitted was simply ignored.
hpUuid
does in fact exist, it was created in the admin panel. But that is an excellent point. – dotancohen Nov 14 '19 at 11:04