Hierarchical items operations

Overview

Hierarchical items are Blog posts, List items, and hierarchical dynamic items.
Blog posts are part of the Blogs module and List items are part of the Lists module.

Get data for the parent module

Getting the data of a parent module of a child type, for example - Blogs or Lists, is the same as getting data for any other module.

To do this, you must execute a GET request to the following endpoint:

{baseurl}/api/default/{entity}

Where {entity} is the entity of the module that you are working with.

Sample request

GET http://mysite.com/api/default/blogs

Sample response

Status code: 200 OK
JSON
{
    "@odata.context": "http://mysite.com/api/default/$metadata#blogs(Id,LastModified,PublicationDate,Title,Description,DateCreated,IncludeInSitemap,UrlName)",
    "value": [
        {
            "Id": "d17f777f-6350-411d-83b1-1d0c5e93996b",
            "LastModified": "2021-04-13T19:19:21Z",
            "PublicationDate": "2021-03-25T16:02:14Z",
            "Title": "Blog 1",
            "Description": "",
            "DateCreated": "2021-03-25T16:02:14Z",
            "IncludeInSitemap": true,
            "UrlName": "blog1"
        },
        {
            "Id": "1f4a2201-df5e-47f5-8552-c8cfdf77a62f",
            "LastModified": "2021-04-13T19:19:08Z",
            "PublicationDate": "2021-04-07T14:59:21Z",
            "Title": "Blog 2",
            "Description": "",
            "DateCreated": "2021-04-07T14:59:21Z",
            "IncludeInSitemap": true,
            "UrlName": "blog2"
        }
    ]
}

Filter items by ParentId

If the request is made for the child type only with the entity of that type, then all items for that type will be returned, regardless of their parent.

To get all child items for a specific parent, you should apply a filter by the ParentId property and execute a GET request to the following endpoint:

{baseurl}/api/default/{entity}?$filter=(ParentId eq {parentItemId})

Where:

  • {entity} is the entity of the child module that you are working with
  • {parentItemId} is the ID of the parent item

Sample request

GET http://mysite.com/api/default/blogposts?$filter=(ParentId eq d17f777f-6350-411d-83b1-1d0c5e93996b)

Sample response

Status code: 200 OK
JSON
{
    "@odata.context": "http://localhost:4242/api/default/$metadata#blogposts(Id,LastModified,PublicationDate,Title,Description,DateCreated,IncludeInSitemap,UrlName,AllowComments,Summary,Content,ParentId)",
    "value": [
        {
            "Id": "c161b300-b593-45da-988e-2408a25d24c0",
            "LastModified": "2021-04-13T19:29:17Z",
            "PublicationDate": "2021-03-25T16:02:20Z",
            "Title": "Sample blog post",
            "Description": "",
            "DateCreated": "2021-03-25T16:02:20Z",
            "IncludeInSitemap": true,
            "UrlName": "sample-blog-post",
            "AllowComments": true,
            "Summary": "Lorem ipsum",
            "Content": "<strong>Lorem Ipsum</strong>&nbsp;is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
            "ParentId": "d17f777f-6350-411d-83b1-1d0c5e93996b"
        }
    ]
}

Create an item with ParentId

To create a hierarchical item, you must execute a POST request to the entity endpoint and specify the item properties in JSON format inside the request body. The ParentId property indicates under which parent you want to create a hierarchical child item.

To create a hierarchical item, execute a POST request to the following endpoint:

{baseurl}/api/default/{entity}

Where {entity} is the entity of the module that you are working with.

You must specify the properties of the item that you want to create in JSON format inside the request body.

Sample request

POST http://mysite.com/api/default/blogposts

Request body
JSON
{
  "Title": "Sample blog post item",
  "ParentId": "dd75e95f-b761-4b62-b0d8-ad251c857d99"
}

Sample response

Status code: 201 Created
JSON
{
    "@odata.context": "http://mysite.com/api/default/$metadata#blogposts/$entity",
    "Id": "97d57528-d9e9-4784-8689-f2e635b721e0",
    "LastModified": "2021-05-25T20:06:05Z",
    "PublicationDate": "2021-05-25T20:06:05Z",
    "Title": "Sample blog post item",
    "Description": "",
    "DateCreated": "2021-05-25T20:06:05Z",
    "IncludeInSitemap": true,
    "UrlName": "8e9a9f29-9558-4cb7-b482-cc01b80c36eb",
    "Tags": [],
    "Category": [],
    "AllowComments": true,
    "Summary": "",
    "Content": "",
    "ParentId": "dd75e95f-b761-4b62-b0d8-ad251c857d99",
    "Provider": "OpenAccessDataProvider",
    "Comments": []
}

Update an item with ParentId

To update a hierarchical item, you must execute a PATCH request to the entity endpoint and specify the item’s properties that you want to modify in JSON format inside the request body.
The ParentId property is not important in this type of action, because you use the itemId itself.

To update a child item, you must execute a POST request to the following endpoint:

{baseurl}/api/default/{entity}({itemId})

Where:

  • {entity} is the entity of the module that you are working with
  • {itemId} is the ID of the item that you want to modify

You must specify all properties that you want to modify in JSON format inside the request body.

Sample request

PATCH http://mysite.com/api/default/blogposts(97d57528-d9e9-4784-8689-f2e635b721e0)

Request body
JSON
{
     "Title": "Updated blog post item"
}

Sample response

Status code: 204 No Content

No response body

Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.