In today’s world sharing digital content across various channel is very common. People create content at a central place and share the same content across various channel/platform sometime various app/mobile app as well.
Sitecore also having multiple ways to share the content. The most common way Sitecore JSS layout service. Another way of sharing the content is Sitecore OData Item Service.
Scope of this post is to talk about Sitecore OData Item Service. So, in which scenario, should we consider this OData Item Service approach?
Suppose you are working on a traditional Sitecore based CMS website (MVC/ASP.Net based website). Either your website got migrated to Sitecore latest version (today’s latest version is 9.3) or you might be created traditional Sitecore website using MVC/ASP.Net. Later-on client want to expose the content to another platform/website/app. Content can be same of different, but they want to keep all the content at the central place and all the available platform/app should be consuming the content placed at common place. In this scenario, Sitecore OData Item Service is the ideal solution.
Sitecore OData Item Service configuration
Step-1:Navigate to the Service -> API Keys item (/sitecore/system/Settings/Services/API Keys)
Step-2: Right click on API Key and choose OData Item API Key
Step-3: Fill the values as per requirement
Database: Enter the database name for which you would like to share content. It would always send content from the mentioned database.
Search Filter: Mention search filter. OOTB value indicates to share the latest version of content.
CORS Origin: You can allow for origins. Use semicolons in case of multiple values. If you want to allow for all domains, you can use star (*).
AllowedControllers: If you want to expose to all the controller, you can use start (*) otherwise you can mention the semicolons separated controllers.
Impersonation User: In case of blank, Sitecore considers Sitecore.Services.AnonymousUser.
Step-4: Publish you OData Item API Key
Now your Sitecore OData Item Service is ready to consume.
How to access/consume Sitecore OData Item Service
OData Item Service API URL format:
URL: {Sitecore_instance_hostname}/sitecore/api/ssc/aggregate/content/Items('{Item_ID/Item_Path}')
Header
Key=sc_apikey
Value={api_key}
Method:GET
We can use Postman to test your OData Item Service:
URL:https://sc93sc.dev.local/sitecore/api/ssc/aggregate/content/Items('{EC04E21D-59BC-4FB1-881C-9D3E04ADD02C}')
We can pass item path as well to get the item details
URL:https://sc93sc.dev.local/sitecore/api/ssc/aggregate/content/Items('/sitecore/content/Demo/BeautyCare/Home/News/A plan to revive a broken economy')
As you can see in the screenshot, it is returning only mentioned item’s details (OOTB fields value). It is not returning values against custom fields or we can say any content.
$expand=Fields
QueryString parameter $expand=Fields can be used to get all the fields available. It would also contain OOTB item property values like Id, Name etc.
https://sc93sc.dev.local/sitecore/api/ssc/aggregate/content/Items('{EC04E21D-59BC-4FB1-881C-9D3E04ADD02C}')?$expand=Fields
$expand=FieldValues
https://sc93sc.dev.local/sitecore/api/ssc/aggregate/content/Items('{EC04E21D-59BC-4FB1-881C-9D3E04ADD02C}')?$expand=FieldValues
It returns given item details with custom fields values.
$select=Id,Name,TemplateName
https://sc93sc.dev.local/sitecore/api/ssc/aggregate/content/Items('{EC04E21D-59BC-4FB1-881C-9D3E04ADD02C}')?$select=Id,Name,TemplateName
It returns values of fields mentioned with $select query string parameter.
$expand=FieldValues($select=NewsTitle,NewsBody)
https://sc93sc.dev.local/sitecore/api/ssc/aggregate/content/Items('{EC04E21D-59BC-4FB1-881C-9D3E04ADD02C}')?$expand=FieldValues($select=NewsTitle,NewsBody)
It returns mentioned item details and custom fields value mentioned with $select
Children
You can use children option to get the children items details of the mentioned item id/path.
https://sc93sc.dev.local/sitecore/api/ssc/aggregate/content/Items('{B8F7AE0F-244D-4D32-8636-E6C892E4C2DF}')/children
You can use children with other mentioned options as well.
https://sc93sc.dev.local/sitecore/api/ssc/aggregate/content/Items('{B8F7AE0F-244D-4D32-8636-E6C892E4C2DF}')/children?$expand=Fields
It would return children items detail with their field’s details and values.
Thanks for your time and good day ahead.
References:
SITECORE CLI LOGIN ERROR - /.well-known/openid-configuration: Bad Gateway
WALKTHROUGH OF ASP.NET RENDERING SDK
SETTING UP ASP.NET RENDERING SDK
DISABLE SITECORE PUBLISHING SERVICE
SETUP SITECORE PUBLISHING SERVICE
SITECORE CONNECT CONNECTOR - CONTENT HUB