SDL Tridion sites 9 Public Content API With GraphQL – Part 1

SDL Tridion sites 9 has couple of new features, but most promising feature is Public Content API (PCA). This API is the new endpoint for content delivery for Sites and Docs. This empowers customers by providing more dynamic and cleaner solutions for their channels.

Content API uses GraphQL, which provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more.

Main Advantages of GraphQL are –

  • Elegant Data Retrieval: Single endpoint and versioning not required.
  • Efficient Querying: Specify the information you need and get data in one single-trip request.
  • Back-end Stability: No need to change client while modifying data.
  • Documentation: Simple & understandable Graph schema with self-documented feature.
  • Large Community: Larger community and larger number of client tools.

So today I am going to share some useful query which will help you if you are using Public Content API with Sites 9 to build and manage your application.

Note*: While installing the Content API, the default endpoint will be something like https://:/cd/api.

Here I am using GraphiQL client (Default in Chrome Browser) for demo purpose.

All you need to do is open your chrome browser and hit the below url https://<host-name&gt;:<port-no>/cd/api/graphiql. Additionally, you can check this if you want to understand how to access Tridion public content API while OAuth is enabled.

Let’s start with a simple query –

In the below example, we request 3 properties of a published page by page id –

{
page(namespaceId:1,publicationId:5,pageId:302)
{
itemId,
publicationId,
url
}
}

Graphql query to gat Page by id
Page with id

Most frequently used query is to retrieve the raw content of a published page –

Here is the query for that:

{
page(namespaceId:1,publicationId:5,pageId:302)
{
itemId,
publicationId,
url,
rawContent
{
data
}
}
}

GraphQL query to get Page Raw Content
Page Raw Content

Similarly you can retrieve the content from component presentation as well –

{
componentPresentation(namespaceId: 1, publicationId: 5, componentId: 311, templateId: 84) {
component {
title
itemId
creationDate
}
}
}

GraphQl query to get Component Presentation

Another interesting query to retrieve the sitemap or navigation for your site is below –

{
sitemap(namespaceId: 1, publicationId: 5) {
id
items
{
id
title
originalTitle
visible
}
}
}

GraphQl query to get Sitemap

You check this blog for complex queries like filtering by items/keywords,sorting, etc.

Hope you like this article! Please add your comments below if you need any additional information.

#TridionSites9 #PublicContentAPI #ContentDelivery #GraphQL #GraphiQL


Leave a comment