0

Using Content Hub (CH) v4.2

I have created a Content Collection called "McDonalds Content Collection" which has an item of Content Type Advertisement.

enter image description here

Now, I would like to fetch all the data/items from the respective collections, For e.g., I want to get all the Advertisements and their data (Title, Image, Description) from "McDonalds Content Collection".

Or just all items in that collection with their details.

Here is my API query:

https://{{hostname}}/api/entities/query?query=Int('id')==93451

93451 is the ID of my Collection item/folder.

This query returns information about the collection and not the items inside it. What should be the query to get only the data inside the collection.

Response

{
    "items": [
        {
            "id": 93451,
            "identifier": "LtgrELltiUyy8kRysWqNmA",
            "cultures": [
                "en-US"
            ],
            "properties": {
                "ContentCollectionName": "McDonalds Content Collection",
                "ContentCollectionDescription": null,
                "PreventPublish": null,
                "PublishStatus": {
                    "identifier": "Published",
                    "labels": {
                        "en-US": "Published"
                    }
                },
                "PublishStatusDetails": null
            },
            "relations": {
                "RoleProxyToContentCollection": {
                    "href": "https://example.com/api/entities/93451/relations/RoleProxyToContentCollection"
                },
                "ContentCollectionToMasterAsset": {
                    "href": "https://example.com/api/entities/93451/relations/ContentCollectionToMasterAsset"
                },
                "ContentRepositoryToContentCollection": {
                    "href": "https://example.com/api/entities/93451/relations/ContentRepositoryToContentCollection"
                },
                "StatusToContentCollection": {
                    "href": "https://example.com/api/entities/93451/relations/StatusToContentCollection"
                },
                "MContentCollectionToAvailableRoute": {
                    "href": "https://example.com/api/entities/93451/relations/MContentCollectionToAvailableRoute"
                },
                "MContentCollectionToActiveState": {
                    "children": [
                        {
                            "href": "https://example.com/api/entities/29917"
                        }
                    ],
                    "inherits_security": true,
                    "self": {
                        "href": "https://example.com/api/entities/93451/relations/MContentCollectionToActiveState"
                    }
                },
                "ContentCollectionToContent": {
                    "href": "https://example.com/api/entities/93451/relations/ContentCollectionToContent"
                },
                "MContentCollectionToStateMachine": {
                    "href": "https://example.com/api/entities/93451/relations/MContentCollectionToStateMachine"
                }
            },
            "created_by": {
                "href": "https://example.com/api/entities/92202",
                "title": "The user who created the entity"
            },
            "created_on": "2023-03-13T07:12:09.5920623Z",
            "modified_by": {
                "href": "https://example.com/api/entities/92202",
                "title": "The user who last modified the entity"
            },
            "modified_on": "2023-03-13T07:13:04.818515Z",
            "entitydefinition": {
                "href": "https://example.com/api/entitydefinitions/M.ContentCollection",
                "title": "The entity definition for this entity"
            },
            "copy": {
                "href": "https://example.com/api/entities/93451/copy",
                "title": "Copy this entity"
            },
            "permissions": {
                "href": "https://example.com/api/entities/93451/permissions",
                "title": "The permissions on this entity"
            },
            "lifecycle": {
                "href": "https://example.com/api/entities/93451/lifecycle",
                "title": "The lifecycle action for this entity."
            },
            "saved_selections": {
                "href": "https://example.com/api/entities/93451/savedselections",
                "title": "The saved selections this entity belongs to"
            },
            "roles": {
                "href": "https://example.com/api/entities/93451/roles",
                "title": "Roles for this entity"
            },
            "annotations": {
                "href": "https://example.com/api/entities/93451/annotations",
                "title": "Annotations for this entity"
            },
            "is_root_taxonomy_item": true,
            "is_path_root": false,
            "inherits_security": true,
            "is_system_owned": false,
            "version": 5,
            "self": {
                "href": "https://example.com/api/entities/93451"
            },
            "renditions": {}
        }
    ],
    "total_items": 1,
    "returned_items": 1,
    "self": {
        "href": "https://example.com/api/entities/query?query=Int(%27id%27)%3D%3D93451",
        "title": "This collection"
    }
}
2
  • https://{{hostname}}/api/entities/query?query=And(Equals(ContentTypeName,'Advertisements'),Equals(ContentCollectionName,'McDonalds Content Collection'))&take=1000 does it work for you? Commented Mar 14, 2023 at 8:27
  • @VadimBirkos Got this error Parsing failure: unexpected 'd'; expected c (Line 1, Column 3); recently consumed: An.
    – sukesh
    Commented Mar 14, 2023 at 9:06

1 Answer 1

3

I have raised a support ticket with Sitecore and the 2nd approach they have suggested, worked for me.

Approach 1:
If you already know the ID of the collection, you can directly use

/api/entities/{id}/relations/ContentCollectionToContent

That output does not contain the items, this is because a ContentCollection can contain a lot of Content and the API returns a list of Content that are in the Collection. To get the information, you will need to navigate to the href and it will have the full data of a singular Content.

enter image description here

If you do not know the ID and require search, then:

/api/entities/query?query=(Definition.Name == "M.ContentCollection" AND String('ContentCollectionName')=='McDonalds Content Collection')

When you retrieve this result, you can get the ID then run the query

api/entities/{id}/relations/ContentCollectionToContent

Approach 2:
You can also do a reverse query on M.Content to find all M.Content in a specific ContentCollection. This also requires you to know the ID of the ContentCollection.
For example:

/api/entities/query?query=(Definition.Name == "M.Content" AND Parent('ContentCollectionToContent').id=={id})

In order to get only "Blogs" or "Advertisements", you could use the same query but append the condition

AND Parent('ContentTypeToContent').id=={id}

where ID is equal to the ID of the Content Type. 9786 for Blog and 9792 for Advertisement.

The related documentation is in https://doc.sitecore.com/ch/en/developers/42/cloud-dev/rest-api--query.html

All queries start with

http://<hostname>/api/entities/query/

Then you can append the query depending on what you need such as Properties, Specific system properties and other parameters such as Relations, Operators and furthermore.

The query provided

/api/entities/query?query=(Definition.Name == "M.Content" AND Parent('ContentCollectionToContent').id=={id})

is used to search for all entities with M.Content as definition AND we are searching all entities that have the relation ContentCollectionToContent == id

Further, I had also requested more info about Selection API's documentation for which Sitecore has responded

Regarding the api/selection that you have mentioned, we are sorry to inform you that the docs are outdated and this is not supported anymore. We have raised a request to the team to change the documentation.

Regarding the documentation, this was missed when the functionality of the product was changed. We will provide feedback to the documentation team regarding this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.