Create item with parent

Hello,

Is there a way to set a parent id while creating an item via the Content Management API ? The model has tree-like capabilities.

Thanks

Hello @jean-remy and welcome to the community!

You can check this out right here: Create a new record - Record - Content Management API

Hi,
Thanks for your message ! I have already read this part of the doc, but setting a parent id was a bit unclear to me.
I can see the category example, where 24 seems to be the foreign ID. If I set a parent key (the same key used in the content delivery API), I have the following error: INVALID_ATTRIBUTES / extraneous_attributes parent.
The code I sent is:

{
    "data": {
        "type": "item",
        "attributes": {
            "name": "A nice name",
            "parent": {
                "id": "195433785"
            },
            "color": {
                "red": 255,
                "green": 255,
                "blue": 255,
                "alpha": 100
            }
        },
        "relationships": {
            "item_type": {
                "data": {
                    "type": "item_type",
                    "id": "123"
                }
            }
        }
    }
}

Do I have to set a special field for it, like for the category ? Will it be in concurrence with a parent field if I set the model as tree-like ?

Thanks your for help !

Hello @jean-remy

If you are using the JS client the request is the following:

 const child1 = await client.items.create({
    item_type: { type: 'item_type', id: '377826' }, //ID of the model of the record
    title: 'Title',
    parent_id: "28419103", //ID of the record that will be a parent
    position: 1,
  });

Let me know if that works!

I have tried my previous example, but instead of setting the parent as an object, I’ve juste set the parent_id, juste like in your example. And it worked !

Thanks a lot for your help !

1 Like