Wednesday 28 January 2015

Set user profile properties using JSOM & JavaScript

User Profile properties were recently made writable from the CSOM. Vesa Juvonen has a great post about it here . In addition to that, I have also blogged about how a Tenant admin can set the user profile properties of the users in the tenant.

In this post, I will show you how to set the current user's profile properties using the JavaScript Client Object Model (JSOM). Please refer to the 2 posts I have mentioned for any additional details around this.

Right now this functionality is only available in SharePoint Online/Office 365. If you want this functionality to come to SharePoint 2013 On-Premises, please create or up-vote on the feedback here: https://officespdev.uservoice.com/

Saturday 24 January 2015

Glimpse of the upcoming Office 365 Video API

Update (21/04/2015): Here is the preview of the Office 365 Video API: https://msdn.microsoft.com/office/office365/APi/video-rest-operations

--------------------------------------------X--------------------------------------------------

A while ago, I wrote a post about getting all the video channels and videos from the Office 365 Video Service.  Shortly after that I got a word from Microsoft that there is going to be a public API for accessing Office 365 Videos. I was allowed to share the information as long as I mentioned that the API is not documented yet and is still being worked upon. So there is a possibility that it might change in the future so it is advised that this should not be used in production until it is fully stable and documented.

Here is how the API will work:

1) Get the right path from the discover endpoint:


https://site.sharepoint.com/sites/team/_api/VideoService.discover

The returned JSON will contain the following values among others:

{
    "IsVideoPortalEnabled": true,
    "VideoPortalUrl": "https://site.sharepoint.com/portals/hub"
}

IsVideoPortalEnabled will be true if your tenant has got Office 365 Video and VideoPortalUrl is the url which we will use to make further REST calls.

2) Get all Video channels with the VideoPortalUrl:


https://site.sharepoint.com/portals/hub/_api/VideoService/Channels

The returned JSON will contain all the channels with their unique GUIDs:

{
            "Description": "",
            "Id": "eaa748d7-97d6-43f1-8780-ce5c8acbf2bb",
            "TileHtmlColor": "#0072c6",
            "Title": "Development"
}

3) Get all videos from a single video channel:


Here, we will use the Id obtained from the previous call to get all the videos from a particular channel:

https://site.sharepoint.com/portals/hub/_api/VideoService/Channels('eaa748d7-97d6-43f1-8780-ce5c8acbf2bb')/Videos

Monday 19 January 2015

Programmatically Follow or Unfollow a Delve Board with the REST API

In one of my previous posts, we saw how you can programmatically add a document to a Delve Board with the REST API. This is a follow up post to that in which we will see how to Follow or Unfollow a Delve board with the REST API. If you haven't already seen the previous article, I suggest you take a look at it because it explains how Delve works under the hood and how you can integrate Delve into your custom Office 365 solutions.

Please bear in mind that since Delve utilizes search internally, you will have to wait for a search crawl to take place in Office 365 before you can see results of the REST operation.

I have used JavaScript and the jQuery.ajax function to make calls to the Signals API. But you can use a variety of other options which support REST.

So without much further ado, here is the code to follow or unfollow a board in Delve:



Sunday 18 January 2015

Get all videos from an Office 365 Video Channel with REST

Update (24/01/2015): I have just got a word from Microsoft that there is going to be a public API for accessing Office 365 Videos. The information I have got is that the API is not documented yet and is still being worked upon. So there is a possibility that it might change in the future so it is advised that this should not be used in production until it is fully stable and documented.

Here is a glimpse of the upcoming video API: http://www.vrdmn.com/2015/01/glimpse-of-upcoming-office-365-video-api.html

Original post follows:

In my previous post, we saw how you can get a list of all the video channels in your Office 365 portal with the REST API. In this post, we will see how to get a list of all the videos in a particular Office 365 Video Channel with the SharePoint REST API.

Each video channel is underpinned by a separate site collection in SharePoint Online. When you upload a video to a channel, it gets uploaded in the "Videos" library of the root web of that site collection. A copy of the video is sent to Azure Media Services which then transcodes it so that it can be played from a number of devices. Since the video is stored in SharePoint Online, the size of the video counts against your Tenant storage.

Since each video channel is a site collection, you can use the REST API to get all sorts of information about the channel including the list of videos.

So this is a channel called "Development" on my Office 365 Video Portal. You can see that there are 3 videos uploaded to this channel:


In order to get the list of videos in a video channel, we need to make a REST call to the SharePoint Search REST API:

_api/search/query?querytext='SiteTitle:"Development" AND ContentTypeId:0x010100F3754F12A9B6490D9622A01FE9D8F01200F9B0E79C5EBC0545B80F5F1B3985E159'&selectproperties='Path,Title,SiteTitle'

The ContentTypeId is the id of the new "Cloud Video" content type and the SiteTitle will be the name of the Channel.

Here is the complete code. I have used JavaScript and the jQuery.ajax function to make calls to the SharePoint REST API. But you can use a variety of other options like the JSOM, CSOM or even the Office 365 APIs. Since all the channels are by default open to users in the tenant, there should not be any major challenges to authentication around this. I haven't tested the code for these APIs myself.



And the logs in my Dev tools console:


Thanks for reading!

Get all documents from an Office 365 Group with REST

In my previous post, we saw how you can get a list of all the groups in your Office 365 portal with the REST API. Now, if you are building a solution on top of the Office 365 platform and want a list of all the documents in a particular Office 365 Group, you can get them using the REST API.

As discussed in my previous post, each group is underpinned by a separate site collection in SharePoint Online. When you upload a document to a group, it gets uploaded in the "Documents" library of the root web of that site collection. So you can use the REST API to get all sorts of information about the group including the list of documents. 

Here is a test group called "Technical Team" I have created in Office 365 for the purpose of this post. I have also uploaded 2 documents to it:



In order to get the list of documents in the group, we need to make a REST call to the SharePoint Search REST API:

_api/search/query?querytext='SiteTitle:"Technical Team" AND ContentTypeId:0x0101007DB6FD427B6228409ED888DF766B27C9'&selectproperties='Title,Path,SiteTitle'

The ContentTypeId is the id of the content type which is associated to the document when a document is uploaded to an Office 365 group.

Here is the complete code. I have used JavaScript and the jQuery.ajax function to make calls to the SharePoint REST API. But you can use a variety of other options like the JSOM, CSOM or even the Office 365 APIs. Since all the groups are by default open to users in the tenant, there should not be major challenges to authentication around this. I haven't tested the code for these APIs myself. 


And the logs in my Dev tools console:



Thanks for reading!

Saturday 17 January 2015

Get all Office 365 Video Channels, Groups and Delve Boards with REST

Office 365 has introduced 3 new portals recently: Videos, Groups and Delve. Behind the scenes, the architecture of Videos and Groups is such that each Video channel is a site collection and so is each Group. For Delve boards, each board is saved as a Tag and when you add a document to a board, the document is tagged with the name of the board.

If you are working on a solution for Office 365 and want to integrate Videos, Groups or Delve, here is how you can get a list of all of them using the SharePoint REST API:

1) Get all Office 365 Video Channels with REST API:


https://siteurl.sharepoint.com/_api/search/query?querytext='contentclass:sts_site WebTemplate:POINTPUBLISHINGTOPIC'&SelectProperties='WebTemplate,Title,Path'&rowlimit=50


2) Get all Office 365 Groups with REST API:


https://siteurl.sharepoint.com/_api/search/query?querytext='contentclass:sts_site WebTemplate:Group'&SelectProperties='WebTemplate,Title,Path'&rowlimit=50


3) Get all Delve Boards with REST API:


https://siteurl.sharepoint.com/_api/search/query?querytext='(Path:"TAG://PUBLIC/?NAME=*")'&Properties='IncludeExternalContent:true'&selectproperties='Path,Title'&rowlimit=50

Friday 9 January 2015

Programmatically add a document to a Delve Board with REST

Microsoft recently launched the Boards feature in Delve, with which you can create Pinterest like boards and add content to them. You can add documents from your SharePoint sites as well as OneDrive for Business sites.  Here is a great introduction to the functionality: http://blogs.office.com/2015/01/07/introducing-boards-office-delve-new-way-organize-share-work/ 
I have been playing around a bit with this feature and have some interesting things to share. So Lets have a look at how this has been implemented under the hood.

1) The same Signals API which I have blogged about here is used in boards. AJAX requests are sent to the /_api/signalstore/signals endpoint when any operations are made in Delve (eg. add document to board)

2) Boards are internally referred to as "Tags". So when you add a document to a board, it gets "Tagged" with the name of the board. More on this later.

3) There seem to be 2 components in play. When you add a document to board, there is an "immediate" add in the front-end as well as a normal add when the incremental crawl adds the document in the Search Index. The front-end immediately  shows the user  that the document is added to a board. This is a very good solution as otherwise the user would have to wait till the incremental crawl has taken place.

Let us have a look at the API now. All the API is doing is adding/removing documents to boards and following/unfollowing boards. Unlike my previous post about modifying relationship signals in the Office Graph, with this API you will not be interfering with your Office Graph relationships so I think you can safely use this API in your solutions.  Now lets take a look at what actually happens under the hood:



There is a new button introduced in the document card. So when you click on "Add to Board" and select a board from the dropdown,  here is the JSON which is sent to the Signals API: 

(click to zoom)


Basically, it has 2 Important pieces of data: 

1) The document gets tagged with the name of the board. This tag is then used by Delve to search and get all documents belonging to a certain board. This is done by the first object with ActionType:Tag and Item Id as the absolute url of the document.

2) The current user is made to follow the Tag (which is the board name) so that it shows up on the left hand side in Delve. This is done by the second object with ActionType: Follow and Item Id: ‘Path=”TAG://PUBLIC/?NAME=MY+TEST+BOARD”  where the name of the board I selected was "My Test Board"

If you want to reproduce this exact behavior in your solution, here is the sample code you can start with. Please be aware that that this code only tags the document with the board name so that it is added to the search index and follows the board so that it appears in your boards in Delve. This does not do the front-end add to the board. So you will have to wait for an incremental crawl to run in Office 365 for the document to get added to the board and show up in Delve. I have observed this can take anywhere from 5 to 30 minutes. 

Here is the code:


The document will get added to the board:


Hope you enjoyed this post. I have plans to follow this up with some code samples which show how to remove documents from boards, unfollow boards and some other new functionality. Thanks for reading.

Saturday 3 January 2015

My Colleagues App powered by Office Graph

This will be a very short post following one of my previous posts about the Office Graph and the GQL. I have taken most of the code there and put it inside a SharePoint Hosted App.

The App queries the Office Graph for the colleagues with whom you closely work with and displays them. Basically, it does the same thing which you see on the left hand side when you log in to Delve. This app can be a good starting point if you want to further develop apps which consume the Office Graph API. You can pick and choose the Delve elements which you want in your app. Also, you can create customized scenarios which leverage the Office Graph and deliver them as Apps for SharePoint.

Since the App requires Search permissions to be granted in the AppManifest, you will need to have the Tenant Admin credentials to install the App. I think this might be a blocker for some people in installing the App. Now fortunately, if you just want to test the functionality out, you can take all the code in the App.js and run it from inside a SharePoint Online page. You do not need tenant admin permissions to execute the code in the page.

This App will only work in SharePoint Online (Office 365) as there is no Office Graph for SharePoint On-Premises at the moment.

The code for the App is part of Office Developer Patterns and Practices repository and is available here:

https://github.com/OfficeDev/PnP/tree/dev/Samples/OfficeGraph.Demo.App