Create relationships between a node and child nodes
POSThttps://euwest.api.elasticpath.com/pcm/hierarchies/:hierarchyID/nodes/:nodeID/relationships/children
Use this endpoint to create relationships between a single parent node and one or more child nodes. You can create a relationship only if:
- The parent node already exists.
- All child nodes already exist.
- Every child node in the body of the request exists in the same hierarchy as the parent node.
- A node is not a parent of itself. An array of child nodes request body must not contain the ID of the parent node in the path.
- All siblings in a hierarchy must have a unique
slug
. Siblings are the child nodes that are related to the same parent.
Sort Order
You can also provide sort_order
information when you create a relationship by adding a meta
object to the array of node reference objects for each child node that requires sorting.
The node with the highest value of sort_order
appears at the top of the response. 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 relationships, all child nodes in the response for Get a Node’s Children request are ordered by theupdated_at
time in descending order. The most recently updated child node appears at the top of the response. - If you set
sort_order
for only a few child nodes or not all, the child nodes withsort_order
value appear first in the response and then other child nodes appear in the order ofupdated_at
time.
You can also specify a sort_order
when creating and updating a node.
- If you create or 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 creating\updating Node A is overwritten. - If you create\update Node A and then you create a relationship with Node B but do not configure a
sort_order
, thesort_order
you specified when you created\updated Node A is not overwritten.
Request
Path Parameters
hierarchyID stringrequired
A unique identifier for the hierarchy.
nodeID stringrequired
A unique identifier for the node.
- application/json
Body
data object[]
Responses
- 200
- 403
- 404
- 422
- 500
Successfully returns the node's children
- application/json
- Schema
- Example (auto)
- set-node-children
Schema
data object
{
"data": {
"id": "string",
"type": "node",
"attributes": {
"name": "string",
"description": "string",
"slug": "string",
"curated_products": [
"string"
],
"locales": {}
},
"relationships": {
"children": {
"data": [
null
],
"links": {
"related": "string"
}
},
"parent": {
"data": {
"type": "node",
"id": "string"
}
},
"products": {
"data": [
null
],
"links": {
"related": "string"
}
}
},
"meta": {
"sort_order": 0,
"created_at": "2020-09-22T09:00:00",
"updated_at": "2020-09-22T09:00:00",
"parent_name": "string",
"owner": "store"
}
}
}
{
"data": {
"type": "node",
"id": "9ea0de15-3347-43dd-8faa-cd32f44a04c7",
"attributes": {
"description": "Latest Ballet Shoes",
"locales": {
"fr-FR": {
"name": "Chaussons de ballet",
"description": "Dernières chaussures de ballet"
}
},
"name": "Ballet Shoes",
"slug": "ballet-shoes"
},
"relationships": {
"children": {
"data": [],
"links": {
"related": "/hierarchies/6183d10c-94b5-4caa-9f12-2f14cb738d41/nodes/9ea0de15-3347-43dd-8faa-cd32f44a04c7/children"
}
},
"products": {
"data": [],
"links": {
"related": "/hierarchies/6183d10c-94b5-4caa-9f12-2f14cb738d41/nodes/9ea0de15-3347-43dd-8faa-cd32f44a04c7/products"
}
}
},
"meta": {
"created_at": "2024-01-11T19:19:50.087Z",
"owner": "store",
"sort_order": 5,
"updated_at": "2024-01-11T19:56:53.695Z"
}
}
}
Forbidden
- application/json
- Schema
- Example (auto)
- internal-server-error
Schema
errors undefined[]required
{
"errors": [
{
"status": "500",
"title": "Internal server error",
"detail": "An internal error has occurred.",
"request_id": "00000000-0000-0000-0000-000000000000",
"meta": {
"missing_ids": [
"e7d50bd5-1833-43c0-9848-f9d325b08be8"
]
}
}
]
}
{
"errors": [
{
"title": "Forbidden",
"status": "403",
"detail": "entity owned by organization"
}
]
}
Bad Request. Not Found.
- application/json
- Schema
- Example (auto)
- internal-server-error
Schema
errors undefined[]required
{
"errors": [
{
"status": "500",
"title": "Internal server error",
"detail": "An internal error has occurred.",
"request_id": "00000000-0000-0000-0000-000000000000",
"meta": {
"missing_ids": [
"e7d50bd5-1833-43c0-9848-f9d325b08be8"
]
}
}
]
}
{
"errors": [
{
"title": "Not Found",
"status": "404"
}
]
}
Bad request. The request failed validation.
- application/json
- Schema
- Example (auto)
- failed-validation
Schema
errors undefined[]required
{
"errors": [
{
"status": "500",
"title": "Internal server error",
"detail": "An internal error has occurred.",
"request_id": "00000000-0000-0000-0000-000000000000",
"meta": {
"missing_ids": [
"e7d50bd5-1833-43c0-9848-f9d325b08be8"
]
}
}
]
}
{
"errors": [
{
"title": "Failed Validation",
"status": "422",
"detail": "<XYZ> can not be empty"
}
]
}
Internal server error. There was a system failure in the platform.
- application/json
- Schema
- Example (auto)
- internal-server-error
Schema
errors undefined[]required
{
"errors": [
{
"status": "500",
"title": "Internal server error",
"detail": "An internal error has occurred.",
"request_id": "00000000-0000-0000-0000-000000000000",
"meta": {
"missing_ids": [
"e7d50bd5-1833-43c0-9848-f9d325b08be8"
]
}
}
]
}
{
"errors": [
{
"status": "500",
"title": "Internal Server Error",
"detail": "There was an internal server error, you can report with your request id.",
"request_id": "635da56d-75a1-43cd-b696-7ab119756b3a"
}
]
}
Authorization: http
name: bearerAuthtype: httpscheme: bearer
- csharp
- curl
- dart
- go
- http
- java
- javascript
- kotlin
- c
- nodejs
- objective-c
- ocaml
- php
- powershell
- python
- r
- ruby
- rust
- shell
- swift
- HTTPCLIENT
- RESTSHARP
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://euwest.api.elasticpath.com/pcm/hierarchies/:hierarchyID/nodes/:nodeID/relationships/children");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer <TOKEN>");
var content = new StringContent("{\n \"data\": [\n {\n \"id\": \"00000000-0000-0000-0000-000000000000\",\n \"type\": \"node\"\n }\n ]\n}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
ResponseClear