Skip to main content

Create relationships between a node and child nodes

POST 

https://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 the updated_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 with sort_order value appear first in the response and then other child nodes appear in the order of updated_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) with a new sort_order, the sort_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, the sort_order you specified when you created\updated Node A is not overwritten.

Request

Responses

Successfully returns the parent node

Authorization: http

name: bearerAuthtype: httpscheme: bearer
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());
Request Collapse all
Base URL
https://euwest.api.elasticpath.com
Auth
Parameters
— pathrequired
— pathrequired
Body
{
  "data": [
    {
      "id": "00000000-0000-0000-0000-000000000000",
      "type": "node"
    }
  ]
}
ResponseClear

Click the Send API Request button above and see the response here!

We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies.