Introduction
In this article, you will learn how to get blogs from the Office 365 Delve sites on the custom components programmatically, using REST API with the various filter options.
Query Options
By default, when the user tries to create a blog post from the Delve user page, the page will be redirected to the user's personal site page. All the posts created on the Delve Blog page will be stored in the user’s personal site; i.e., under “/portals/personal/userfirstname/” site.
Some of the fields that can be queried are the content types, file types, and the file extensions. Only these field values are unique for the blogs created on the Office 365 blog site, which will not be similar to other items. Some of the unique properties and values are:
- Content type - The blogs are stored on the portal, which uses the story page content type.
- Secondary File Extensions - The file extension is aspx page, but the secondary file extension which is used is PointPub, and is unique.
- File Type - The file type of the blog is PointPub.
We will see how we can query to get the desired results, using search REST API.
Using content type
First, we will find out the content type of the story page manually from the Office 365 site.
- From personal site collection, navigate to see all the lists folders and then select the pages folder. (Or just append “/portals/personal/userfirstname/ppg” to the URL and open to see the pages library directly).
- Go to the library settings of the pages library.
- Click the Story Page content type. If content type is not found, go to the advanced settings and allow the content types.
- From the URL of story page content type, get Ctype value. Ctype values show the content type ID of the respective content type.
We need to build the search REST API URL to query the content.
The search REST API, using content type, will look as shown below:
http://siteurl/_api/search/query?querytext=’ContentTypeId:yourstorypagecontenttypeId
Using File Type
We can also query the blogs using the file type. The file type used for the blog is PointPub. The information is stored in JSON format in PointPub files. The file contains the information like Title, SubTitle, Author, Published data, Value etc. The Value contains blog content for each blog.
The search REST API, using file type, will look as shown below:
https://siteurl/_api/search/query?QueryText='FileType:PointPub'
Instead of using file type, you can also use the secondary file extension property to filter out the blog data.
https://siteurl/_api/search/query?QueryText='SecondaryFileExtension:PointPub'
We will use Jquery Ajax call to query and get the blog details. In the code snippet given below, I have used file type to get all the blog data present on the Office 365 site using search API. Similarly, other search REST API URL’s can be used to retrieve the blog results.
- $.ajax({
- url: "/_api/search/query?querytext='filetype:PointPub'",
- type: "GET",
- async: false,
- headers: { "accept": "application/json;odata=verbose" },
- success: function(data){
- var blogInfo = data.d.query.PrimaryQueryResult.RelevantResults;
- var blogResults = blogInfo.Table.Rows.results;
- console.log("Title : "+blogResults[0].Cells.results[3]);
- console.log("Author : "+blogResults[0].Cells.results[4]);
- },
- error: function(data){
- }
- });
In the example given above, the title and author values are retrieved for the first blog present in the collection. Similarly, other properties or blog content can be retrieved from the collection by changing blogResults[i].Cells.results[j] result set.
Summary
Thus, you have learned how to retrieve blogs from Office 365 blog sites, using REST API with various query options.