• PXM Hierarchies/
    PXM Nodes API/
    Create a Node

    Create a Hierarchy Node

    POST Create a Node in a Hierarchy

    https://api.moltin.com/pcm/hierarchies/:hierarchyId/nodes
    

    Creates a node in the specified hierarchy.

    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 the updated_at time in descending order, with the most recently updated child node first.
    • If you set sort_order for only a few child nodes or not all, the child nodes with a sort_order value appear first and then other child nodes appear in the order of updated_at time.

    You can also specify a sort_order when creating a node relationship.

    • If you create a node (Node A) with a sort_order and then you create a relationship for Node A with another node (Node B), the sort_order you specified when creating Node A is overwritten.
    • If you create 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 Node A is not overwritten.

    Parameters

    Path parameters

    NameRequiredTypeDescription
    hierarchyIdRequiredstringThe unique identifier of the hierarchy.

    Headers

    NameRequiredTypeDescription
    AuthorizationRequiredstringThe Bearer token to grant access to the API.

    Body

    Required. By default, the parent of the node is the hierarchy root node. To create a node with a different parent, specify the parent node in the relationships.parent section.

    NameRequiredTypeDescription
    typeRequiredstringAlways: node
    attributes.nameRequiredstringA name for the node. Names must be unique among sibling nodes in the hierarchy, but otherwise a name can be non-unique. Cannot be null.
    attributes.descriptionOptionalstringA description of the node.
    attributes.slugOptionalstringA slug for the node. Slugs must be unique among sibling nodes in the hierarchy, but otherwise a slug can be non-unique.
    relationships.parent.data.typeOptionalstringAlways: node
    relationships.parent.data.idOptionalstringThe node ID for the parent node. The new node is created as a child of this parent node.
    attributes.localesOptionalobjectThe product details localized in the supported languages. For example, product names or descriptions.
    metaOptionalobjectThe 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 POST https://api.moltin.com/pcm/hierarchies/0e119de2-5fb0-4bca-9b84-b3fc6c903007/nodes \
         -H "Authorization: Bearer XXXX" \
         -H "Content-Type: application/json" \
         -d $'{
             "data": {
               "type": "node",
               "attributes": {
                 "name": "Exotic Fruit",
                 "description": "Exotic Fruit",
                 "slug": "Exotic-Fruit"
               },
               "relationships": {
                 "parent": {
                   "data": {
                     "id": "e3a35410-94ed-435e-a006-d88b4eaaefbf",
                     "type": "node"
                   }
                 }
               },
               "meta": {
                 "sort_order": 2
               }
             }
           }'
    

    Response Example

    201 Created

    
    
        "data": {
            "type": "node",
            "id": "5992f585-feb9-46dd-af0d-ef76ac34ba88",
            "attributes": {
                "description": "Exotic Fruit",
                "name": "Exotic Fruit",
                "slug": "Exotic-Fruit"
            },
            "relationships": {
                "children": {
                    "data": [],
                    "links": {
                        "related": "/hierarchies/046c5c21-4b28-4945-9a59-b100b7a5e533/nodes/5992f585-feb9-46dd-af0d-ef76ac34ba88/children"
                    }
                },
                "parent": {
                    "data": {
                        "type": "node",
                        "id": "e3a35410-94ed-435e-a006-d88b4eaaefbf"
                    }
                },
                "products": {
                    "data": [],
                    "links": {
                        "related": "/hierarchies/046c5c21-4b28-4945-9a59-b100b7a5e533/nodes/5992f585-feb9-46dd-af0d-ef76ac34ba88/products"
                    }
                }
            },
            "meta": {
                "created_at": "2022-06-08T13:18:51.172Z",
                "owner": "store",
                "sort_order": 2,
                "updated_at": "2022-06-08T13:18:51.172Z"
            }
        }
    }
    

    Was this helpful?

    Previous
    Get a Node