Retrieve Video Portal Detail
First, we will see how we can retrieve the video portal information from Office 365 using SharePoint 2013 REST Search API.
The video portal is a part of the Point Publishing hub site. The site template used to create the portal is POINTPUBLISHINGHUB. The REST search API can be used along with the Web template ID to get the relevant information. Web template property should be used in query parameter to get the channels using search. Template ID should be passed as the Web template value.
The search API will be,
- https://siteurl/_api/search/query?QueryText='WebTemplate:POINTPUBLISHINGHUB'
The following code snippet shows the JQuery Ajax call to get the video portal information from Office 365 site, using search API:
- $.ajax
- ({
- "http://siteurl/_api/search/query?QueryText='WebTemplate:POINTPUBLISHINGHUB'",
- type: "GET",
- async: false,
- headers: { "accept": "application/json;odata=verbose" },
- success: function(data){
- var portalInfo = data.d.query.PrimaryQueryResult.RelevantResults;
-
- var portalResults = portalInfo.Table.Rows.results;
- for(var i = 0; i< portalResults.length; i++){
- console.log("Title : "+portalResults[i].Cells.results[3].Value);
- console.log("Created By : "+portalResults[i].Cells.results[4].Value);
- console.log("portal URL : "+portalResults[i].Cells.results[6].Value);
- }
-
- },
- error: function(data){
- }
- });
Retrieve Channels
The channels are separate site collections present on the portal. The site template used to create a channel (site collection) on the video portal is POINTPUBLISHINGTOPIC. Hence, we can use the template ID to query the portal to get the channels available.
The search API will be,
- https://siteurl/_api/search/query?QueryText='WebTemplate:POINTPUBLISHINGTOPIC'
Some of the parameters that can be retrieved using the above URL are Channel Name, Created by, Channel URL, etc.
The following code snippet shows the JQuery Ajax call to get the video channels:
- $.ajax
- ({
- url: "http://siteurl/_api/search/query?QueryText='WebTemplate:POINTPUBLISHINGTOPIC'",
- type: "GET",
- async: false,
- headers: { "accept": "application/json;odata=verbose" },
- success: function(data){
- var channelInfo = data.d.query.PrimaryQueryResult.RelevantResults;
-
- console.log("Available Channels Count : " + channelInfo.RowCount);
- var channelResults = channelInfo.Table.Rows.results;
- for(var i = 0; i< channelResults.length; i++){
- console.log("Title : "+channelResults[i].Cells.results[3].Value);
- console.log("Created By : "+channelResults[i].Cells.results[4].Value);
- console.log("Channel URL : "+channelResults[i].Cells.results[6].Value);
- }
-
- },
- error: function(data){
- }
- });
Retrieve Videos
Next, we will see how we can retrieve the videos from the portal in different ways.
Using List REST API
From the channels identified, we will access the videos from the respective channels. REST API is used to query SharePoint list items that will be used. To access a video from one single channel, find the following REST List API URL, given below:
- https://channelurl/_api/web/lists/GetByTitle('Videos')/Items
Channel URL is the channel path name, found from the previous query.
To select necessary properties for the videos, use select parameter and specify the properties. Some of the properties displayed in my example are Title, Author Name, and Video URL. Here, to get the author name, an expanded query needs to be used.
The following code snippet shows the Jquery Ajax call to get the videos present on the specified channel, using List API:
- $.ajax
- ({
- url: "http://videoportal_url/_api/web/lists/GetByTitle('Videos')/Items?$select=Title,FileRef,Author/Title&$expand=Author",
- type: "GET",
- async: false,
- headers: { "accept": "application/json;odata=verbose" },
- success: function(data){
- if(data.d != null && data.d.results.length > 0){
- var videoResults = data.d.results;
-
- console.log("Available Videos Count : " + videoResults.length);
- for(var i = 0; i< videoResults.length; i++){
- console.log("Title : "+videoResults[i].Title);
- console.log("Created By : "+videoResults[i].Author.Title);
- console.log("Video URL : "+videoResults[i].FileRef);
- }
- }
-
- },
- error: function(data){
- }
- });
Using Search REST API Query
In the section above, we have seen how we can retrieve the videos from the channels using List REST API. Now, we will see how we can retrieve the videos (same set of information) from the channel using search REST API.
The content type used for video is cloud video. Navigate to SharePoint Video library from channel site and find out the content, type of list, cloud video, and content type. The search API will be,
- https://siteurl/_api/search/query?QueryText=%27contenttypeid:list_cloudvideo_contenttypeid%27
The following code snippet shows the Jquery Ajax call to get the videos, present on the specified channel, using the list video content type.
- $.ajax
- ({
- url: "http://siteurl/_api/search/query?QueryText='list_cloudvideo_contenttypeid'",
- type: "GET",
- async: false,
- headers: { "accept": "application/json;odata=verbose" },
- success: function(data){
- var videosInfo = data.d.query.PrimaryQueryResult.RelevantResults;
-
- console.log("Available Videos Count on Channel : " + videosInfo.RowCount);
- var videoResults = videosInfo.Table.Rows.results;
- for(var i = 0; i< videoResults.length; i++){
- console.log("Title : "+videoResults[i].Cells.results[3].Value);
- console.log("Created By : "+videoResults[i].Cells.results[4].Value);
- console.log("Video URL : "+videoResults[i].Cells.results[6].Value);
- }
-
- },
- error: function(data){
- }
- });
Summary
Thus, you have learned how to retrieve video portal information, channels, and videos using SharePoint REST Search API and List API.