Update a Hierarchy Node
PUT
Update a Hierarchy Node
https://api.moltin.com/pcm/hierarchies/:hierarchyId/nodes/:nodeId
Updates the specified node in a hierarchy. You can do a partial update, where you specify only the field value to change.
Sort Order
You can sort the order of your nodes, regardless of where the nodes are in the hierarchy.
You can do this by adding a meta
object to the body of your request and specifying a sort_order
value.
"meta": {
"sort_order": 1
}
The node with the highest value of sort_order
is displayed first. For example, a node with a sort_order
value of 3
appears before a node with a sort_order
value of 2
.
- If you don’t provide
sort_order
when creating nodes, all child nodes in the response for Get a Node’s Children request are ordered by theupdated_at
time in descending order, with the most recently updated child node first. - If you set
sort_order
for only for a few child nodes or not all, the child nodes with asort_order
value appear first and then other child nodes appear in the order ofupdated_at
time.
You can also specify a sort_order
when creating a node relationship.
- If you update a node (Node A) with a
sort_order
and then you create a relationship for Node A with another node (Node B), thesort_order
you specified when updating Node A is overwritten. - If you have updated Node A and then you create a relationship with Node B but do not configure a
sort_order
, thesort_order
you specified when you updated Node A is not overwritten.
Parameters
Path parameters
Name | Required | Type | Description |
---|---|---|---|
hierarchyId | Required | string | The unique identifier of the hierarchy. |
nodeId | Required | string | The unique identifier of the node in the hierarchy. |
Headers
Name | Required | Type | Description |
---|---|---|---|
Authorization | Required | string | The Bearer token to grant access to the API. |
Body
Specify whichever attributes
you want to change. The values of the other attributes
remain the same. If the attributes
section is empty, the node is not updated.
Name | Required | Type | Description |
---|---|---|---|
type | Required | string | Always: node |
id | Required | string | The unique identifier of the node. Must match the node ID specified in the request path. |
attributes.name | Optional | string | An updated name. Names must be unique among sibling nodes in the hierarchy, but otherwise names can be non-unique. Cannot be null. |
attributes.description | Optional | string | An updated description. |
attributes.slug | Optional | string | An updated slug. Slugs must be unique among sibling nodes in the hierarchy, but otherwise slugs can be non-unique. |
attributes.locales | Optional | object | The product details localized in the supported languages. For example, product names or descriptions. |
meta | Optional | object | The sort_order for each node. This value determines the order of nodes in the response for the Get a Node’s Children request. |
Request Example
curl -X PUT https://api.moltin.com/pcm/hierarchies/0e119de2-5fb0-4bca-9b84-b3fc6c903007/nodes/d167d384-d2cf-4d05-ad41-6fc567855765 \
-H "Authorization: Bearer XXXX" \
-d $'{
"data": {
"type": "node",
"id": "d167d384-d2cf-4d05-ad41-6fc567855765",
"attributes":{
"description": "Electric stoves and ovens - UPDATED",
}
}
}'
Response Example
200 OK
{
"data": {
"type": "node",
"id": "d167d384-d2cf-4d05-ad41-6fc567855765",
"attributes": {
"description": "Electric stoves and ovens - UPDATED",
"name": "Electric Ranges",
"slug": "Electric-Ranges-MA2",
"locales": {
"fr-FR": {
"name": "Cuisinières électriques",
"description": "Cuisinières et fours électriques - MISE À JOUR"
}
}
},
"relationships": {
"children": {
"data": [],
"links": {
"related": "/hierarchies/0e119de2-5fb0-4bca-9b84-b3fc6c903007/nodes/d167d384-d2cf-4d05-ad41-6fc567855765/children"
}
},
"parent": {
"data": {
"type": "node",
"id": "e2f3372c-89ed-49ae-a9c7-0dc1888f10ec"
}
},
"products": {
"data": [],
"links": {
"related": "/hierarchies/0e119de2-5fb0-4bca-9b84-b3fc6c903007/nodes/d167d384-d2cf-4d05-ad41-6fc567855765/products"
}
}
}
}
}