How to use OData service to expose Sitecore content?

Recently we received one request from a Client to migrate the content from Sitecore 7.2 application to a newer website on another platform. So the client was expecting the data in either XML or JSON format.

First we thought of creating a custom .Net utility to read the Sitecore data from the Content tree and generating JSON out of it. But while doing R&D, I found out that we have OData item service which can be used to expose Sitecore content in JSON format.

The challenge was that service is not supported Sitecore 7.2 so we installed fresh instance of Sitecore XP 9.3, created Sitecore package of the required items in 7.2 and installed the package in 9.3.

It is very easy to setup the OData item service.

  1. Go to Content Editor.
  2. Navigate to API Keys item (/sitecore/system/Settings/Services/API Keys)
    API Keys Item
  3. Create an item based on OData Item API key template.
    OData Item API Keys Template
  4. Based on the requirement fill in the details as Database, Search Filter, CORS origins, & Allowed Controls.
    Item
    So we wanted the data from Master database & latest version of the item so accordingly the Database & Search Filter fields were filled. In case your site is hosted then you specify the endpoints that can connect to you sitecore instance to read the JSON through OData item services in CORS Origins.
  5. Save the item.
  6. Note down the item id of this item (In my case: {0708DD25-70F1-4384-9109-E8724D2B9901})
    Item ID

Now we have setup the OData Item service and we have the content to be migrated in our instance.

The new task is to form the Item Service URL. So I wanted the News Articles to be migrated in JSON format with value of all it’s fields.

The URL I created for this is: http://sitecoretrial.dev.local/sitecore/api/ssc/aggregate/content/Items?$filter=TemplateName eq ‘Article‘&sc_apikey={0708DD25-70F1-4384-9109-E8724D2B9901}&$expand=FieldValues

Note that the template name of the News Artciles was Article (highlighted in blue) & the API key for my instance was the one highlighted in blue. If you want to learn more about URL creation based on the different requirements then you can refer here.

Once you have the URL ready, you can simply browse it in the Browser and it will ask you to Save a Items.json file which will be your content in JSON format.
JSON

This is a very easy and effortless approach to migrate the content from Sitecore to any other third party application.

Thank you… Keep Learning… Keep Sitecoring.. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s