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.
- Go to Content Editor.
- Navigate to API Keys item (/sitecore/system/Settings/Services/API Keys)
- Create an item based on OData Item API key template.
- Based on the requirement fill in the details as Database, Search Filter, CORS origins, & Allowed Controls.
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. - Save the item.
- Note down the item id of this item (In my case: {0708DD25-70F1-4384-9109-E8724D2B9901})
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.
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.. 🙂