Test the update attribute endpoint with your own data
Update an existing custom attribute
This endpoint allows you to update an existing custom attribute by providing its ID and the fields you want to modify.
Only the fields included in the request will be updated. All other fields will remain unchanged.
PUT https://api.commerceclarity.com/api/v1/attributes/update/{id}
| Parameter | Type | Required | Description |
|---|---|---|---|
id |
string | Required | The unique attribute identifier (Attribute ID or attribute_id) |
| Parameter | Type | Required | Description |
|---|---|---|---|
name |
string | Optional | New display name for the attribute |
attribute_id |
string | Optional | New unique identifier (slug) for the attribute |
type |
string | Optional | New attribute type |
scope |
string | Optional | New scope (global or family-specific) |
description |
string | Optional | New description or help text |
options |
array | Optional | Array of option change objects. Only the options listed are affected; existing options not included are preserved automatically. |
options[].action |
string | Required | Operation to perform: "new" (add), "update" (rename/edit), or "delete" (remove). |
options[].new_name |
string | Conditional | Required for new and update. The display label of the option. |
options[].<existing_key> |
any | Conditional | Required for update and delete. Include the normalised key of the existing option as an extra field (e.g. "red": null) so the API can identify which option to target. |
options[].new_value_id |
string | Optional | Optional custom identifier for the option. Used with new and update. |
family_ids |
array | Optional | New list of family IDs if scope is family |
is_enabled |
boolean | Optional | Enable or disable the attribute |
curl -X PUT "https://api.commerceclarity.com/api/v1/attributes/update/507f1f77bcf86cd799439011" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Product Color",
"description": "Updated color attribute description",
"options": [
{ "action": "new", "new_name": "Black" },
{ "action": "new", "new_name": "White" },
{ "action": "update", "yellow": null, "new_name": "Golden Yellow" },
{ "action": "delete", "green": null }
]
}'
$client = new \GuzzleHttp\Client();
$attributeId = '507f1f77bcf86cd799439011';
$response = $client->put('https://api.commerceclarity.com/api/v1/attributes/update/' . $attributeId, [
'headers' => [
'Authorization' => 'Bearer ' . $apiToken,
'Content-Type' => 'application/json',
],
'json' => [
'name' => 'Product Color',
'description' => 'Updated color attribute description',
'options' => [
['action' => 'new', 'new_name' => 'Black'],
['action' => 'new', 'new_name' => 'White'],
['action' => 'update', 'yellow' => null, 'new_name' => 'Golden Yellow'],
['action' => 'delete', 'green' => null],
],
]
]);
$data = json_decode($response->getBody(), true);
const attributeId = '507f1f77bcf86cd799439011';
const response = await fetch(`https://api.commerceclarity.com/api/v1/attributes/update/${attributeId}`, {
method: 'PUT',
headers: {
'Authorization': `Bearer ${apiToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Product Color',
description: 'Updated color attribute description',
options: [
{ action: 'new', new_name: 'Black' },
{ action: 'new', new_name: 'White' },
{ action: 'update', yellow: null, new_name: 'Golden Yellow' },
{ action: 'delete', green: null }
]
})
});
const data = await response.json();
{
"success": true,
"data": {
"attribute": {
"_id": "507f1f77bcf86cd799439011",
"attribute_id": "color",
"name": "Product Color",
"type": "single-select",
"scope": "global",
"is_essential": false,
"description": "Updated color attribute description",
"options": {
"red": { "value": "Red" },
"blue": { "value": "Blue" },
"golden_yellow": { "value": "Golden Yellow" },
"black": { "value": "Black" },
"white": { "value": "White" }
},
"family_ids": [],
"families": [],
"brand_id": "507f1f77bcf86cd799439010",
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-20T14:45:00Z"
}
}
}
{
"success": false,
"message": "Attribute not found"
}