OData Services in Sitecore


Today I am going to explain the OData services available within Sitecore.

Firstly, let's discuss OData. OData (Open Data Protocol) is a standard protocol for creating and consuming REST APIs. It provides a way to interact with the data sources via HTTP and HTTPS. It supports a few formats such as JSON and XML.

Sitecore a leading CMS (Content Management System) has built-in support for OData services. Sitecore provides an out-of-the-box OData service that can be used to expose the Sitecore items and fields as a REST API.

By default, the Sitecore OData service provides read-only access to the Sitecore items and fields. However, you can also customize the service to allow create, update, and delete operations too.

Setup OData Service in Sitecore

1. Go to Content Editor from Sitecore Launchpad.


2. Navigate to /sitecore/system/Settings/Services/API Keys and add an OData Item API key.


3. Now based on your requirement fill in the details such as Database, Search Filter, CORS Origins, Allowed Controllers, Impersonation User, and Throttle Strategy.


4. Save the item and note down the Item ID.

5. Publish the item to use the OData Item API key.

To access the OData service, you need to add the /sitecore/api/ssc/ prefix to the URL of your Sitecore instance. For example, the URL for accessing the OData service for my Sitecore instance would have the prefix “https://sitecore103sc.dev.local/sitecore/api/ssc/”.

You can also use the OData services to query the Sitecore items and fields by using the OData query syntax. The OData query syntax supports some of the operators such as $filter, $orderby, $expand, $count, $skip, $select, etc.

Accessing an Item using OData Service with Field Values

The URL for accessing the item with field values having an Item ID “110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9” will be “https://sitecore103sc.dev.local/sitecore/api/ssc/item/110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9?sc_apikey={3A95842D-FAF3-437A-9F4F-D573E0723BB6}”.


Another way for accessing the item with field values having an Item ID “110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9” will be “https://sitecore103sc.dev.local/sitecore/api/ssc/Item/110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9?sc_apikey={3A95842D-FAF3-437A-9F4F-D573E0723BB6}&$expand=FieldValues”.


Accessing an Item using OData Service without Field Values

The URL for accessing the item without field values having an Item ID “110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9” will be “https://sitecore103sc.dev.local/sitecore/api/ssc/aggregate/content/Items('110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9')?sc_apikey={3A95842D-FAF3-437A-9F4F-D573E0723BB6}”.


Accessing an Item by Path using OData Service without Field Values

The URL for accessing the item without field values having a Path “/sitecore/content/Home” will be “https://sitecore103sc.dev.local/sitecore/api/ssc/aggregate/content/Items('/sitecore/content/Home')?sc_apikey={3A95842D-FAF3-437A-9F4F-D573E0723BB6}”.


Accessing an Item using OData Service with Fields Information

The URL for accessing the item without field values having an Item ID “110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9” will be “https://sitecore103sc.dev.local/sitecore/api/ssc/aggregate/content/Items('110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9')?sc_apikey={3A95842D-FAF3-437A-9F4F-D573E0723BB6}&$expand=Fields”.


Accessing an Item using OData Service with specific Field Values

The URL for accessing the item with field values having an Item ID “110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9” will be “https://sitecore103sc.dev.local/sitecore/api/ssc/aggregate/content/Items('110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9')?sc_apikey={3A95842D-FAF3-437A-9F4F-D573E0723BB6}&$expand=FieldValues($select=Title)”.


Accessing an Item using OData Service with Field Values and Standard Fields

The URL for accessing the item with field values and standard values having an Item ID “110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9” will be “https://sitecore103sc.dev.local/sitecore/api/ssc/aggregate/content/Items('110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9')?sc_apikey={3A95842D-FAF3-437A-9F4F-D573E0723BB6}&$expand=FieldValues,StandardFieldValues”.


Accessing an Item using OData Service with Children

The URL for accessing the item with Children having an Item ID “110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9” will be “https://sitecore103sc.dev.local/sitecore/api/ssc/aggregate/content/Items('110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9')?sc_apikey={3A95842D-FAF3-437A-9F4F-D573E0723BB6}&$expand=Children”.


Accessing an Item using OData Service with Parent

The URL for accessing the item with Children having an Item ID “110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9” will be “https://sitecore103sc.dev.local/sitecore/api/ssc/aggregate/content/Items('110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9')?sc_apikey={3A95842D-FAF3-437A-9F4F-D573E0723BB6}&$expand=Parent”.


Accessing an Item using OData Service with specific Fields

The URL for accessing the item with specific fields having an Item ID “110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9” will be “https://sitecore103sc.dev.local/sitecore/api/ssc/aggregate/content/Items('110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9')?sc_apikey={3A95842D-FAF3-437A-9F4F-D573E0723BB6}&$select=ID,Name”.


References




Happy Coding
Chirag Goel

I am a developer, likes to work on different future technologies.

Post a Comment (0)
Previous Post Next Post