Category Archives: Office 365 – Video

Programmez #190 : Developing with Delve and Office 365 Video REST APIs

Interested in developing applications that use Delve and/or Office 365 Video using REST APIs ?

Take a look to my article in the latest issue of Programmez, a magazine available in French-speaking countries (France, Belgium, Switzerland, Luxemburg, Canada…).

Programmez 190

Advertisements

NSURLSession/NSURLConnection HTTP load failed when trying to stream an Office 365 Video on iOS 9

Yesterday, I was playing with Office 365 Video and I wanted to be able to play/stream videos from Office 365 into an iOS app.

The first step to be able to read a video was to retrieve the streaming URL of that video in Azure Media Services (which is used behind Office 365 to offer streaming capabilities).

It’s pretty simple using the Office 365 REST API :

https://tenant.sharepoint.com/portals/hub/_api/VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Videos(guid'01234567-abcd-cded-1234-1234567890ab')/GetPlaybackUrl(0)

When you execute that request, you retrieve the URL to play/stream the video from Azure Media Services in HLS format (HTTP Live Streaming). This URL should look something like :

https://cvprdb302v.cloudvideo.azure.net/api/ManifestProxy?playbackUrl=https://cdn-cvprdb302m01.streaming.mediaservices.windows.net/.../Manifest(format=m3u8-aapl)&token=...

To play/stream the video into an iOS app, you can use the built-in video player (AVPlayer) which is compatible with HLS format. To do that, you just have to write few lines of code :

let URL = NSURL(string: "...")  // Put here the URL retrieved from GetPlaybackUrl
let playerViewController = AVPlayerViewController()
playerViewController.player = AVPlayer(URL: URL!)
presentViewController(playerViewController, animated: true, completion: nil)
playerViewController.player?.play()

If you run this code on iOS 8, there’s no problem and everything should work fine. But if you run the same code on iOS 9, it should throw an exception like that :

NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9802)

You have to wonder why the same code don’t work on the last version of iOS. The answer is quite simple : App Transport Security (ATS).

In iOS 9, there are new security mechanisms that have been implemented to ensure that, when an app uses network communications, the traffic is encrypted to ensure confidentiality.

But if you look the URL of the video, it uses HTTPS so the traffic is encrypted. Then why an exception was thrown ? It seems that the ciphers used to encrypt the traffic are considered as unsafe by iOS 9.

What to do to be able to play/stream the video in that case ? It’s possible to configure how ATS works by modifying the info.plist file of your app.

There are many ways to do that and the most easiest is to add the following key/values :

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSAllowsArbitraryLoads</key>
  <true/>
</dict>

For in-house apps or development purposes, it’s very useful but not secured because ATS is completely disabled. If you read Apple’s documentation, it also could be a reason to reject your app if you want to publish it on the AppStore.

If you want to manage more precisely which URLs can be used without problems with ATS, you have to add exception domains in your info.plist as you can see above :

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>mediaservices.windows.net</key>
    <dict>
      <key>NSIncludesSubdomains</key>
      <true/>
      <key>NSExceptionRequiresForwardSecrecy</key>
      <false/>
    </dict>
    <key>cloudvideo.azure.net</key>
    <dict>
      <key>NSIncludesSubdomains</key>
      <true/>
      <key>NSExceptionRequiresForwardSecrecy</key>
      <false/>
 </dict>
</dict>

With these settings, we configure ATS to allow more ciphers to encrypt HTTPS traffic, for two domains (and all sub-domains) used by Azure Media Services to stream videos.

If you prefer to use the editor available in Xcode to edit your info.plist, rather than manually editing the XML file, you just have to add key/values like :

Office365 Video - App Transport Security

Now if we execute our app, we are able to play/stream the video without any exceptions. 😉

Generate thumbnail of a document stored in SharePoint from its URL

In a previous article, we have seen how to generate a document thumbnail from its metadata (siteId, webId, uniqueId, docId…) retrieved from the search engine.

With these metadata, you just have to build and call an URL such as the following :

https://tenant.sharepoint.com/_layouts/15/getpreview.ashx?guidFile=<GUID>&guidSite=<GUID>&guidWeb=<GUID>&docid=<Int>&metadatatoken=<String>

Although easy to implement, this solution is not convenient every time, especially when you don’t use the search engine to retrieve data.

For example, when you use the Video REST API or the SharePoint REST API to manipulate list items, you don’t retrieve some of the required properties to generate the preview as described in our previous article.

One solution should be to query the search engine for the associated file to retrieve required metadata, then build and call the URL to generate the preview. This solution works very well but it’s pretty inefficient because you have to make 2 requests for each thumbnail.

A better solution based on the same HTTP Handler

Last week, I was working on different things around Office 365 and I discovered a better solution based on the same HTTP Handler.

It’s possible, rather than passing many parameters (siteId, webId, docId…), to pass only one parameter called ‘path’.

This parameter expects a value equal to the URL of the document/file for which you want to generate a thumbnail. To generate a preview, the URL should look like this :

https://tenant.sharepoint.com/portals/hub/_layouts/15/getpreview.ashx?path=https%3A%2F%2Ftenant.sharepoint.com%2Fportals%2Fcommunity%2FpVid%2FBiking%2520to%2520Work.mp4

In the sample above which generates a thumbnail for a video stored in an Office 365 video channel), you just have to encode the path of the file, and add it to the querystring for the ‘path‘ parameter.

I have tested with many file types (Word, Excel, PowerPoint, MP4…), stored in different containers (document libraries, video channels…) and it works for each of them.

For information, this solution is used by Delve to generate thumbnails for video files stored in Office 365 Video 😉

Delve - HomePage

Search videos using the Office 365 Video REST API

Office 365 is an awesome solution to share videos in a dedicated portal, organized in different channels. Channels are used (for example) to split videos by themes or categories.

But if you create a lot of channels in your organization or if you have a lot of videos in each channel, it may be pretty difficult to find relevant videos.

If you want to create an application on top of Office 365 Video, it’s interesting to know that the REST API exposes capabilities to search videos, globally at the service level, or at the channel level.

Build and submit search queries

When you want to use the Office 365 Video REST API, you have to submit requests to the endpoint which is only accessible through the portal URL as you can see below.

https://tenant.sharepoint.com/portals/hub/_api/VideoService

As we previously said, this endpoint exposes search capabilities at two different levels :

  • Video Service (across all channels)
  • Channel

Depending on which level you want to search videos, you have to build requests by appending path components as you can see below :

Across all channels

https://tenant.sharepoint.com/portals/hub/_api/VideoService/Search/Query

On a specific channel

https://tenant.sharepoint.com/portals/hub/_api/VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Search/Query

Add parameters to the querystring to specify search criterias

To retrieve only information that you want, you have to add some parameters to the querystring. Three possibilites are offered to you :

  • querytext
  • startItemIndex
  • itemLimit

As you can imagine, the most important parameter is querytext which allows you to make fulltext searches. startItemIndex and itemLimit are used to perform paging operations.

For example if you want to search the first 10 videos which contains the ‘Awesome’ word, across all channels, your request should look something like that :

https://tenant.sharepoint.com/portals/hub/_api/VideoService/Search/Query?querytext='Awesome'&itemLimit=10

In the same manner, if you want to retrieve the same videos on a specific channel, your query should look something like that :

https://tenant.sharepoint.com/portals/hub/_api/VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Search/Query?querytext='Awesome'&itemLimit=10

By querying those URLs, you will retrieve a list of videos. Each video is described by the following structure :

<entry>
<id>https://tenant.sharepoint.com/portals/hub/_api/VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Videos(guid'01234567-abcd-cded-1234-1234567890ab')</id>
<category term="SP.Publishing.VideoItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" href="VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Videos(guid'01234567-abcd-cded-1234-1234567890ab')" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Author" type="application/atom+xml;type=entry" title="Author" href="VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Videos(guid'01234567-abcd-cded-1234-1234567890ab')/Author" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Owner" type="application/atom+xml;type=entry" title="Owner" href="VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Videos(guid'01234567-abcd-cded-1234-1234567890ab')/Owner" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PeopleInMedia" type="application/atom+xml;type=feed" title="PeopleInMedia" href="VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Videos(guid'01234567-abcd-cded-1234-1234567890ab')/PeopleInMedia" />
<title />
<updated>2015-01-01T01:00:00Z</updated>
<author>
  <name />
</author>
<content type="application/xml">
  <m:properties>
    <d:ChannelID m:type="Edm.Guid">01234567-abcd-cded-1234-1234567890ab</d:ChannelID>
    <d:CreatedDate m:type="Edm.DateTime">2015-01-01T01:00:00Z</d:CreatedDate>
    <d:Description />
    <d:DisplayFormUrl>https://tenant.sharepoint.com/portals/community/pVid/Forms/DispForm.aspx?ID=1</d:DisplayFormUrl>
    <d:FileName>AwesomeVideo.mp4</d:FileName>
    <d:OwnerName>Stephane Cordonnier</d:OwnerName>
    <d:ServerRelativeUrl>/portals/community/pVid/AwesomeVideo.mp4</d:ServerRelativeUrl>
    <d:ThumbnailUrl>https://tenant.sharepoint.com/portals/community/pVid/AwesomeVideo.mp4.PNG?VideoPreview=1</d:ThumbnailUrl>
    <d:Title>My Awesome Video</d:Title>
    <d:ID m:type="Edm.Guid">01234567-abcd-cded-1234-1234567890ab</d:ID>
    <d:Url>https://tenant.sharepoint.com/portals/community/pVid/AwesomeVideo.mp4</d:Url>
    <d:VideoDurationInSeconds m:type="Edm.Int32">120</d:VideoDurationInSeconds>
    <d:VideoProcessingStatus m:type="Edm.Int32">2</d:VideoProcessingStatus>
    <d:ViewCount m:type="Edm.Int32">10</d:ViewCount>
    <d:YammerObjectUrl>https://tenant.sharepoint.com/portals/hub/_layouts/15/videoplayer.aspx?v=https%3A%2F%2Ftenant%2Esharepoint%2Ecom%2Fportals%2Fcommunity%2FpVid%2FAwesomeVideo%2Emp4</d:YammerObjectUrl>
  </m:properties>
</content>
</entry>

Retrieve popular videos across all channels, or for a specific channel

It’s great to be able to search for videos but if you use the web version of Office 365 Video, you probably saw that the homepage displays popular videos. I guess you wonder how to retrieve those videos ?

The search endpoint mentioned above has special syntax to get those data. If you want to retrieve popular videos globally or for a specific channel, you have to submit requests using the following URLs:

https://tenant.sharepoint.com/portals/hub/_api/VideoService/Search/Popular
https://tenant.sharepoint.com/portals/hub/_api/VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Search/Popular

As for simple searches, you can use startItemIndex and itemLimit to perform paging through popular videos.

If you want more information on the Office 365 Video REST API, you can read the official documentation on the MSDN website : https://msdn.microsoft.com/office/office365/APi/video-rest-operations.

Office 365 Video REST API Overview

On April 16th, Office 365 Video has started moving from first release to general availability worldwide.

At the same time, a new REST API was launched and documented to be able to build your own applications (mobile, desktop, web…) on top of Office 365 Video.

Let’s get started to learn how to use this new API to perform basic operations.

Check if Office 365 Video is available and discover the API endpoint

Because Office 365 video has started to be deployed on all tenants few days ago, it’s not necessary available for your organization and/or your Office 365 administrator can disable it.

To check if the service is currently available and/or usable, you can send a request to the following URL :

https://tenant.sharepoint.com/_api/VideoService.Discover

By querying this URL, you will retrieve a response as you can see below :

<entry xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml" xml:base="https://tenant.sharepoint.com/_api/">
<id>https://tenant.sharepoint.com/_api/VideoService.Discover</id>
<category term="SP.Publishing.VideoServiceDiscoverer" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" href="VideoService.Discover" />
<title />
<updated>2015-01-01T01:00:00Z</updated>
<author>
  <name />
</author>
<content type="application/xml">
  <m:properties>
    <d:ChannelUrlTemplate>https://tenant.sharepoint.com/portals/hub/_layouts/15/videochannel.aspx?channel={0}</d:ChannelUrlTemplate>
    <d:IsVideoPortalEnabled m:type="Edm.Boolean">true</d:IsVideoPortalEnabled>
    <d:PlayerUrlTemplate>https://tenant.sharepoint.com/portals/hub/_layouts/15/videoplayer.aspx?v={0}</d:PlayerUrlTemplate>
    <d:VideoPortalLayoutsUrl>https://tenant.sharepoint.com/portals/hub/_layouts/15</d:VideoPortalLayoutsUrl>
    <d:VideoPortalUrl>https://tenant.sharepoint.com/portals/hub</d:VideoPortalUrl>
  </m:properties>
</content>
</entry>

In this response, you can check if Office 365 video is available and activated (cf. IsVideoPortalEnabled).

If the service is available, you can retrieve the VideoPortalUrl which is the path used by the new REST API to get the list of channels, get a video, upload a video, etc…

Retrieve the list of available channels

In Office 365 Video, when a user wants to upload a video and share it with colleagues, the video is stored (classified) in a channel.

By default, channels are created by administrators and viewable by all the users. To retrieve the list of all available (viewable) channels, you have to query the VideoPortalUrl retrieved previously as you can see below :

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

By querying that URL, you will retrieve a list of channels. Each channel is described by the following structure :

<entry>
<id>https://tenant.sharepoint.com/portals/hub/_api/VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')</id>
<category term="SP.Publishing.VideoChannel" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" href="VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Search" type="application/atom+xml;type=entry" title="Search" href="VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Search" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/SpotlightVideos" type="application/atom+xml;type=feed" title="SpotlightVideos" href="VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/SpotlightVideos" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Videos" type="application/atom+xml;type=feed" title="Videos" href="VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Videos" />
<title />
<updated>2015-01-01T01:00:00Z</updated>
<author>
  <name />
</author>
<content type="application/xml">
  <m:properties>
    <d:Description />
    <d:Id m:type="Edm.Guid">01234567-abcd-cded-1234-1234567890ab</d:Id>
    <d:TileHtmlColor>#2A8DD4</d:TileHtmlColor>
    <d:Title>Community</d:Title>
    <d:YammerEnabled m:type="Edm.Boolean">true</d:YammerEnabled>
  </m:properties>
</content>
</entry>

 

If you want to retrieve the list of channels on which you are able to perform edit operations (e.g upload, update, delete), you just need to query the following URL (the structure of the response if the same as for viewable channels) :

https://tenant.sharepoint.com/portals/hub/_api/VideoService/CanEditChannels

Retrieve the list of videos for a channel

Now that you’re able to get the list of channels, you certainly want to retrieve the list of available videos for that channel.

It’s pretty simple and you just have to query that URL (replace the GUID with the appropriate value based on IDs retrieved in the list of channels) :

https://tenant.sharepoint.com/portals/hub/_api/VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Videos

By querying that URL, you will retrieve a list of videos for the selected channel. Each video is described by the following structure :

<entry>
<id>https://tenant.sharepoint.com/portals/hub/_api/VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Videos(guid'01234567-abcd-cded-1234-1234567890ab')</id>
<category term="SP.Publishing.VideoItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<link rel="edit" href="VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Videos(guid'01234567-abcd-cded-1234-1234567890ab')" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Author" type="application/atom+xml;type=entry" title="Author" href="VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Videos(guid'01234567-abcd-cded-1234-1234567890ab')/Author" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Owner" type="application/atom+xml;type=entry" title="Owner" href="VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Videos(guid'01234567-abcd-cded-1234-1234567890ab')/Owner" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/PeopleInMedia" type="application/atom+xml;type=feed" title="PeopleInMedia" href="VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Videos(guid'01234567-abcd-cded-1234-1234567890ab')/PeopleInMedia" />
<title />
<updated>2015-01-01T01:00:00Z</updated>
<author>
  <name />
</author>
<content type="application/xml">
  <m:properties>
    <d:ChannelID m:type="Edm.Guid">01234567-abcd-cded-1234-1234567890ab</d:ChannelID>
    <d:CreatedDate m:type="Edm.DateTime">2015-01-01T01:00:00Z</d:CreatedDate>
    <d:Description />
    <d:DisplayFormUrl>https://tenant.sharepoint.com/portals/community/pVid/Forms/DispForm.aspx?ID=1</d:DisplayFormUrl>
    <d:FileName>AwesomeVideo.mp4</d:FileName>
    <d:OwnerName>Stephane Cordonnier</d:OwnerName>
    <d:ServerRelativeUrl>/portals/community/pVid/AwesomeVideo.mp4</d:ServerRelativeUrl>
    <d:ThumbnailUrl>https://tenant.sharepoint.com/portals/community/pVid/AwesomeVideo.mp4.PNG?VideoPreview=1</d:ThumbnailUrl>
    <d:Title>My Awesome Video</d:Title>
    <d:ID m:type="Edm.Guid">01234567-abcd-cded-1234-1234567890ab</d:ID>
    <d:Url>https://tenant.sharepoint.com/portals/community/pVid/AwesomeVideo.mp4</d:Url>
    <d:VideoDurationInSeconds m:type="Edm.Int32">120</d:VideoDurationInSeconds>
    <d:VideoProcessingStatus m:type="Edm.Int32">2</d:VideoProcessingStatus>
    <d:ViewCount m:type="Edm.Int32">10</d:ViewCount>
    <d:YammerObjectUrl>https://tenant.sharepoint.com/portals/hub/_layouts/15/videoplayer.aspx?v=https%3A%2F%2Ftenant%2Esharepoint%2Ecom%2Fportals%2Fcommunity%2FpVid%2FAwesomeVideo%2Emp4</d:YammerObjectUrl>
  </m:properties>
</content>
</entry>

 

As you can see above, you are able to retrieve a lot of information about the video (title, author, duration, number of views, URL…).

But if you watch the URL value, it corresponds to the physical location of the video stored in a SharePoint site (each channel is a SharePoint site collection).

If a lot of users try to access the video at the same time, it may have an impact of the performance of your tenant because SharePoint is not optimized for that kind of usage.

When a video is uploaded in a channel, it’s also sent to Azure Media Services (at no additionnal costs) to be able to use the streaming capabilities of Azure.

If you want to retrieve the corresponding URL of your video in Azure Media Services, you just need to query the following URL (replace the GUIDs for the channel and the video with appropriate values) :

https://tenant.sharepoint.com/portals/hub/_api/VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Videos(guid'01234567-abcd-cded-1234-1234567890ab')/GetPlaybackUrl(0)

At the end of the URL, you can see a value when calling the GetPlaybackUrl method. When the value is equal to zero, it indicates you want to use the HTTP Live Streaming (HLS) capability of Azure Media Services.

HLS is compatible with all devices (mobile, desktop, web…) but if you want to use another format/protocol, you can pass ‘1’ for the value, which indicates you want to use Smooth Streaming/MPEG-DASH instead of HLS. See the example below :

https://tenant.sharepoint.com/portals/hub/_api/VideoService/Channels(guid'01234567-abcd-cded-1234-1234567890ab')/Videos(guid'01234567-abcd-cded-1234-1234567890ab')/GetPlaybackUrl(1)

For security reasons, videos stored in Azure Media Services are encrypted so if you want to use Smooth Streaming/MPEG-DASH instead of HLS, you need one additionnal step (retrieve an access token) to be able to use and access the retrieved URL.

Conclusion

We’ve just give you an overview of how to access and use the new REST API available with Office 365 Video to retrieve channels and videos but many other operations are available in this API (upload videos, delete videos, update metadata…).

The new API is already used by the Office 365 Video application for iPhone : https://itunes.apple.com/app/id953685679

If you want more information on the Office 365 Video REST API, you can read the documentation on the MSDN website : https://msdn.microsoft.com/office/office365/APi/video-rest-operations.

Search documents and generate a preview with Office 365 REST API

Since Delve and Office Graph were announced last year, you may have asked how it’s working and if it’s possible to retrieve documents from all your SharePoint sites, and not only content from Delve/Office Graph.

Delve - HomePage

In the rest of this article, we are not going be focused on Delve / Office Graph (maybe in a future post) but we’re going to explain how to search any kinds of documents and how to generate a preview for these.

If you’re not familiar with Office 365 REST API, you are able to perform searches on content stored in your SharePoint sites by using the search endpoint.

https://<tenant>.sharepoint.com/_api/search

This endpoint offers 2 different possibilities to submit a query to the SharePoint search index.

For the first one, you just need to submit an HTTP GET request to URL below with some parameters in the querystring.

https://<tenant>.sharepoint.com/_api/search/query?querytext='OneDrive'

This first usage is described by a lot of blogs thus, do a search with Google/Bing if you want more information on this.

The second possibility is to submit an HTTP POST request to :

https://<tenant>.sharepoint.com/_api/search/postquery/

This second choice is more flexible if your search query is complex or very long (remember that an URL cannot exceed ~4000 characters).

Below you can see and example of the body you have to include in your HTTP POST message. (Important : SharePoint is case sensitive when you submit your search query).

{
    request =     {
        Querytext = "(ContentTypeId:0x010100F3754F12A9B6490D9622A01FE9D8F012*)",
        RowLimit = 20,
        SelectProperties =         (
            DocId,
            DefaultEncodingURL,
            DocumentPreviewMetadata,
            SiteId,
            Title,
            UniqueId,
            WebId
        ),
        StartRow = 0,
        TrimDuplicates = True
    }
}

This query will return the first 20 documents from Office 365 Video (based on the ContentTypeId). We only select properties needed (DocId, SiteId, Title…) and want to exclude duplicates.

The StartRow parameter allows you to perform paging if necessary.

There are many more kinds of parameters you can pass to your search query. Refer to the following MSDN page if you need more information : https://msdn.microsoft.com/en-us/library/office/jj163876.aspx

Now that we are able to retrieve a list of documents (Office 365 videos in our case), how to generate a preview for each of them ?

By analyzing how Delve is working, you can see that thumbnails are generated by calling an URL with the following format :

https://<tenant>.sharepoint.com/_layouts/15/getpreview.ashx?guidFile=<GUID>&guidSite=<GUID>&guidWeb=<GUID>&docid=<Int>&metadatatoken=<String>

As you can see, these parameters are similar to those we have put in our search query :

  • guidFile = UniqueId
  • guidSite = SiteId
  • guidWeb = WebId
  • docId = DocId

But what about the metadatatoken parameter ? That’s the magic because we have put a particular property named DocumentPreviewMetadata in our search query.

If you look at the search result response, this property is returned in the following format.

{
    Key = DocumentPreviewMetadata,
    Value = "{\"previews\":[{\"h\":187,\"src\":0,\"w\":300}],\"token\":\"300x187x0\"}",
    ValueType = "Edm.String"
}

As you can see, the value for the property is a JSON serialized object in which you are able to get the width, the height and the token associated to the file preview. If the file has multiple preview (e.g. many slides in a PowerPoint document), the previews array will contain multiple values.

If you deserialize this value and put the token value into the metadatatoken parameter of the URL mentioned previously, you have all the items necessary to call the URL and to generate the preview for all your documents.

Thanks for reading this article and I hope it will help you to develop awesome apps by using the Office 365 REST API 😉