Showing posts with label o365. Show all posts
Showing posts with label o365. Show all posts

Thursday 16 June 2016

Retrieve Channels and Videos from Office 365 Video Portal Using REST Video API

In this post, you will learn how to retrieve the video portal information, video channels and videos of respective channel from the Office 365 sites using REST Video APIs (Newly introduced for Video Portal).

Microsoft has introduced new APIs for working with video portal. The hierarchy of information storage will be,
  • Video portal is present in an Office 365 instance.
  • Video Portal consists of channels.
  • Channels in turn consist of many videos.


Retrieve Video Portal Details:


First we will see how we can retrieve video portal URL of the Office 365 site using REST Video API.

The API used to get the video portal information will be “https://siteurl/_api/VideoService.Discover”. The properties which can be accessed from this operation are, Video Site Page URL, Channel Template URL, Player template URL and Video Site URL.

The following code snippet shows the JQuery Ajax call to get the video portal information from the Office 365 site.
  1. $.ajax
  2. ({  
  3.     url: "/_api/VideoService.Discover",  
  4.     type: "GET",  
  5.     headers: { "accept""application/json;odata=verbose" },  
  6.     success: function(data)
  7.     {  
  8.         var videoSiteInfo = data.d;  
  9.         console.log("Video Site Page URL : " + videoSiteInfo.O365VideoPageUrl);  
  10.         console.log("Video Channel URL : " + videoSiteInfo.ChannelUrlTemplate);  
  11.         console.log("Player URL : " + videoSiteInfo.PlayerUrlTemplate);  
  12.         console.log("Video Site URL : " + videoSiteInfo.VideoPortalUrl);          
  13.     },  
  14.     error: function(data){  
  15.     }  
  16. });  


Retrieve Channels:


On the Video portal, you can start creating channels. The channels are used to categorize the videos. Creating channel literally means you are going to create site collections.

To get the channels from the video portal, the video portal URL should be used with REST Video API to pull the information. The REST API URL will be https://videositeurl/_api/VideoService/Channels. Here video site URL is the component which we have identified in the above section.

Next, we will see how we can retrieve information about particular channel. Identify the channel and get the channel id manually or by using the previous operation. The operation will be very similar to the above one. Only difference is Channel id is passed to get the particular channel information.
https://videositeurl/_api/VideoService/Channels('Channel-GUID')

The following code snippet shows the JQuery Ajax call to get the channel details from the Office 365 Video portal.
  1. $.ajax
  2. ({  
  3.     url: "/portals/hub/_api/VideoService/Channels"// Pass Channel id to get particular channel info  
  4.     type: "GET",  
  5.     headers: { "accept""application/json;odata=verbose" },  
  6.     success: function(data)
  7.     {  
  8.     var channelInfo = data.d.results[0]; // First Channel  
  9.         console.log("channel Name : " + channelInfo.Title);  
  10.         console.log("channel URL : " + channelInfo.ServerRelativeUrl);  
  11.       // Similarly other properties can be retrieved
  12.     },  
  13.     error: function(data){  
  14.     }  
  15. });  


Retrieve Videos from Channels: 


Now we will see how we can retrieve videos from a particular channel using REST Video API. With the video portal URL and channel ID identified in the above sections, get the channel videos using below API.
https://videositeurl/_api/VideoService/Channels('Channel-GUID')/Videos

The operation will fetch us all the videos from the channel. Using for each, loop through the result set to get the details of each video. The properties which can be viewed are File name, video url, Author details, video download URL, view count, thumbnail url, duration, video uploaded date and channel details. The following code snippet shows the operation in detail.

Now we will see how we can retrieve particular video detail. This is again similar to the above operation. Once you identify the video id, you can pass it using query to SharePoint along with channel id to get more information about single video. The same set of properties will be retrieved here. The REST Video API will be,
https://videositeurl/_api/VideoService/Channels('Channel-GUID')/Videos('Video-GUID') 

The following code snippet shows the JQuery Ajax call to get the video details of a channel from the Office 365 Video portal.
  1. $.ajax
  2. ({  
  3.     url: "/portals/hub/_api/VideoService/Channels('Channel-GUID')/Videos",  
  4.     type: "GET",  
  5.     async: false,  
  6.     headers: { "accept""application/json;odata=verbose" },  
  7.     success: function(data)
  8.     {  
  9.         var videoInfo = data.d.results[0]; // First Video  
  10.         console.log("Video Name : " + videoInfo.FileName);  
  11.         console.log("Video URL : " + videoInfo.Url);  
  12.     // Similarly other properties can be retrieved  
  13.     },  
  14.     error: function(data){  
  15.     }  
  16. });  

Monday 13 June 2016

An Overview of Office 365 Delve Blogs


In this post, you will see about Office 365 Delve Blogs component. The blog feature is supported on Office 365 delve, where users will be able to create or view blogs on the Office 365 portal.


Blog:


Microsoft has introduced new blogs feature on Office 365 delve. Delve creates separate site collection for portals (/portals/hub). It has app pages folder within the site collection which has 2 pages. Here, Point publishing page is present. The delve blogs are stored or can be viewed from point publishing page. Each o365 account will have access to these sites and pages (which is created by default).
At the bottom of delve user page, users will get the blog component.

If users click on all posts link, it will take us to user's blog page where users can add or view their blog posts. Users can create from delve home page or blog page. The following snapshot shows user's blog page.


The saved blogs will immediately start appearing on the blogs page, but not on the delve user page. It will take few minutes of time for published blogs to be available on delve user page. The delay is because of search crawl. The blog posts component on the delve users page is rendered based on the search index. Search should run periodically to get display the blog posts.
Now we will see how we can retrieve the blog posts available on delve user’s page. Users can create new blog by clicking new post tile or by clicking new post from delve user page.

Here, users can put their own data with the existing design. There are multiple options for users to put their content.
  • Images can be added as banner for the blog post.
  • Title or subtitle can be given to the blog post.
  • By clicking the plus icon on the blog content area, Users can put the blog content with text, document links or images, etc.

For inserting blog content, there are many options. Users can insert text with available custom format or can insert the content from the existing portal.

Using Text Section

  • Header – To add header sub title for sections 
  • Text – Paragraph content can be inserted using this component. Within this component, other styling options can also applied. 

  • Bulleted list or Numbered list – To put the content in list format. 
  • Pull Quote – To highlight the paragraph or lines.


Using Content Section

  • Image – Images can be inserted from portal or local drive. 
  • Document – The documents present on the portal using link or directly from one drive. Once inserted, Office Web App preview of the document will be available on the page. The preview page can also be set for document inserted from settings of OWA component.

  • Video – Videos can be inserted from the video portal.
You can insert any element anywhere on the blog to complete it. Then you can save and publish the blog.

Retrieve Delve Boards And Their Documents From Office 365 Using REST API


In this post, you will learn how to retrieve boards and documents (added to board) from Office 365 Delve, using REST API. Jquery Ajax and search APIs are used to perform the operation.


Retrieve Boards:


Board is just a way to categorize the documents on the site. The operation shown below will fetch all the board names that the user has added it to his documents. Say for example, user has added board called “Cricket” to two documents and “Tennis” to one document. This means the user is following two boards. They are Cricket and Tennis (these values will be listed on Delve left pane). There can be boards added by other users as well, which will not be listed on the user's Delve page. We will see how we can retrieve these boards from Office 365 Delve.
  • The search API is used to pull the information. 
  • The necessary parameters to query the board details are the query text and properties. In the query text, we need to pass the path to get the board names available on Delve. We need to set the external content to be true in the properties, so it will retrieve all the properties related to the board.
  • Using Ajax call with get method, retrieve the board names. Set the necessary parameters in the Ajax method.
    1. var getBoardURL = "/_api/search/query?QueryText='Path:\"TAG://PUBLIC/?NAME=*\"'&Properties='IncludeExternalContent:true'";  
    2. $.ajax  
    3. ({  
    4.     url: getBoardURL,  
    5.     method: 'GET',  
    6.     async: false,  
    7.     headers:   
    8.     {  
    9.         "Accept""application/json; odata=verbose"  
    10.     },  
    11.     success: function(response)   
    12.     {  
    13.         // Get the exact result set.    
    14.         var resultSet = response.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results;  
    15.         // Loop through result set to get the properties for each boards.    
    16.         for (var i = 0; i < resultSet.length; i++)   
    17.         {  
    18.             console.log("Title    : " + resultSet[i].Cells.results[3].Value);  
    19.             console.log("Actor ID : " + resultSet[i].Cells.results[1].Value);  
    20.         }  
    21.     },  
    22.     error: function(data) {}  
    23. });    
From the response, we can get the board names, their corresponding actor IDs, path and other board details.



Retrieve Documents from board:


  • The board actor ID (identified in the section, above) is used to retrieve the respective board documents. 
  • To retrieve the documents, we will the use search API again to pull the information. 
  • The necessary parameters are the query text and properties. In the query text, pass * or any keyword to retrieve the documents. In the properties parameter, pass the graph query along with actor ID (identified in the section, above) of the board and action ID. (Here, action ID should be 1045 to denote the board). Here, we are passing single board actor ID to retrieve the particular board documents. You can change the logic to get multiple board's documents.
    1. var actorId = ""// Set the actor id of board (can be identified from above section) to see the documents.    
    2. getDocumentURL = "/_api/search/query?QueryText='*'&Properties='GraphQuery:actor(" + actorId + "\\,action\\:1045)'"  
    3. $.ajax  
    4. ({  
    5.     url: getDocumentURL,  
    6.     method: 'GET',  
    7.     async: false,  
    8.     headers:  
    9.     {  
    10.         "Accept""application/json; odata=verbose"  
    11.     },  
    12.     success: function(response)   
    13.     {  
    14.         // Get the exact result set.    
    15.         var resultSet = response.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results;  
    16.         // Loop through result set to get the documents from the board.    
    17.         for (var i = 0; i < resultSet.length; i++)   
    18.         {  
    19.             console.log("Title    : " + resultSet[i].Cells.results[3].Value);  
    20.             console.log("URL      : " + resultSet[i].Cells.results[6].Value);  
    21.             // Similarly other values can be retrieved     
    22.         }  
    23.     },  
    24.     error: function(data) {}  
    25. });   
Note: In these cases, you can check the result values in a Browser debugger console. You can change the logic to display the results on the pages. Place these scripts on the page, using the Web parts (Content Editor / Script Editor / any custom Web part). 

Add/Remove Custom Ribbon Items on SharePoint List Using CSOM PowerShell


In this post, you will learn how to add or remove custom ribbon items (user actions) on SharePoint list using CSOM Powershell on SharePoint 2013 / SharePoint 2016 / SharePoint online sites.



Steps Involved:


The following prerequisites need to be executed before going for any operations using CSOM PowerShell on SharePoint sites.
  1. Add the references using the Add-Type command with the necessary reference paths. The necessary references are Client.dll, Client.Runtime.dll and publishing.dll.
    Add-Type -Path

    "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"

    Add-Type -Path

    "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

    Add-Type -Path

    "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Publishing.dll"
  2. Initialize client context object with the site URL.
    1. $siteURL = ""  
    2. $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)  
  3. If you are trying to access SharePoint Online site then you need to setup the site credentials with credentials parameter and load it to the client context. 
    1. #Not required for on premise site - Start  
    2. $userId = ""  
    3. $pwd = Read-Host -Prompt "Enter password" -AsSecureString  
    4. $creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, $pwd)  
    5. $ctx.credentials = $creds  
    6. #Not required for on premise site - End  
  4. If you are trying to access the SharePoint on premise site then the credentials parameter is not required to be set to the context but you need to run the code on the respective SharePoint Server or you need to pass the network credentials and set the context.
    1. #Credentials for on premise site - Start  
    2. $pwd = Read-Host -Prompt "Enter password" -AsSecureString  
    3. $creds = New-Object System.Net.NetworkCredential("domain\userid", $pwd)  
    4. $ctx.Credentials = $creds  
    5. #Credentials for on premise site - End  



Add Custom Ribbon Items (User Actions) to List:


We will see how we can add the custom ribbon items (actions) to the SharePoint list.
  • Get the existing user action collection. Access the web and get the existing user actions using UserCustomActions property. Load and execute the property.
    1. $web = $ctx.Site.RootWeb  
    2. $userActions = $web.UserCustomActions  
    3. $ctx.Load($userActions)   
    4. $ctx.ExecuteQuery()   
  • Then to the user actions collection, add new custom action. The necessary parameters for new action are registration id, title, registration type and location.
    • Registration Id - Corresponding List template id to add the user action. For example, here 100 denotes the custom list templates.
    • Registration Type -  Denotes association type.
    • location - Custom Action location.
      1. $newRibbonItem = $userActions.Add()  
      2. $newRibbonItem.RegistrationId = "100"  
      3. $newRibbonItem.Title = "Custom Ribbon"  
      4. $newRibbonItem.RegistrationType = [Microsoft.SharePoint.Client.UserCustomActionRegistrationType]::List  
      5. $newRibbonItem.Location = "CommandUI.Ribbon"  
  • Build the xml for the new definition with correspoding handler. In this case, I have considered button as a custom action and associated alert box to the action. You can build your own logic on command action parameter. Location in the xml denotes the place where item will be placed.
  • Update and execute the query.
    1. $ribbonUI = '<CommandUIExtension>  
    2.                     <CommandUIDefinitions>  
    3.                         <CommandUIDefinition Location="Ribbon.List.Actions.Controls._children">  
    4.                             <Button Id="Ribbon.List.Actions.ShowAlert" Alt="Show Alert" Sequence="100"  
    5.                                  Command="ShowRibbonAlert"  
    6.                                  LabelText="Custom Alert"  
    7.                                  TemplateAlias="o1"  
    8.                                  Image32by32="_layouts/15/images/alertme.png"  
    9.                                  Image16by16="_layouts/15/images/alertme.png" />  
    10.                        </CommandUIDefinition>  
    11.                     </CommandUIDefinitions>  
    12.                     <CommandUIHandlers>  
    13.                         <CommandUIHandler Command="ShowRibbonAlert"  
    14.                              CommandAction="javascript:alert(''hi'');"/>  
    15.                     </CommandUIHandlers>  
    16.                 </CommandUIExtension >'  
    17.   
    18. $newRibbonItem.CommandUIExtension = $ribbonUI  
    19. $newRibbonItem.Update()  
    20. $ctx.Load($newRibbonItem)  
    21. $ctx.ExecuteQuery()  
After executing the above steps you can find the new ribbon item on the sharepoint custom list (list tab). The following snapshot depicts the custom ribbon action.



Remove Custom Ribbon Items (User Actions) from List:


We will see how we can remove the custom ribbon items (actions) from the SharePoint list.
  • Get the existing user action collection. Access the web and get the existing user actions using UserCustomActions property. Load and execute the property.
    1. $web = $ctx.Site.RootWeb  
    2. $userActions = $web.UserCustomActions  
    3. $ctx.Load($userActions)   
    4. $ctx.ExecuteQuery()   
  • Delete items
    • If items exists, use filter conditions and filter the ribbon items and assign items in to an array to delete. (Multiple items can not be deleted from the result variable, since the items are present in the enumeration variable. So we are assigning it to array and deleting the items or actions)
    • From the array, delete the items and finally execute the query.
      1. $itemsToDelete = @()  
      2. if($userActions.Count -le 0){  
      3.     Write-Host "No Ribbon Items found to delete"  
      4. }  
      5. else{  
      6.     foreach($userAction in $userActions){  
      7.         $itemsToDelete += $userAction                  
      8.     }  
      9.     foreach($item in $itemsToDelete){  
      10.         Write-Host "Deleting Ribbon Item : " $item.Title  
      11.         $item.DeleteObject()  
      12.     }  
      13.     $ctx.ExecuteQuery()  
      14. }  
The above operation deletes all the custom ribbon items from the site. You can filter out to the exact ribbon item from the for each loop and delete the item(s).