Get video thumbnails from SharePoint using Microsoft Graph

SharePoint Online has a service to generate and return links to media thumbnails stored in the libraries, It works great for a lot of formats but mp4 videos are no longer supported.

This article describes an alternative process to retrieve the thumbnails for the videos you have stored in the libraries using Microsoft Graph.

Nowadays everything is available through Microsoft Graph and with a few queries you will be able to get 3 resolutions for the video thumbnail.

All the steps described below can be accomplished on Microsoft Graph Explorer and then reused with your preferred development language making the appropriate rest calls.

In order to get the thumbnail, you will need to get first:

  • The ID of the site where the videos is stored
  • The ID of the drive (library) where the video is stored
  • The ID of the video

Get the Site ID

To get the ID of the site you can do the following request, more information about it can be found here.

GET /sites/{hostname}:/{server-relative-path}

Example: Since we only need the ID it can be specified in the query string

https://graph.microsoft.com/v1.0/sites/handsonsp.sharepoint.com:/sites/contosodronelanding?$select=id

Get the Drive ID

Now that you got the ID for the site you need to get the ID for the library, doing the following request, more information about it can be found here

GET /sites/{siteId}/drives

Example:In this example I’m requesting the ID and the name of the library in case it’s needed to iterate through them

https://graph.microsoft.com/v1.0/sites/handsonsp.sharepoint.com,89e9f807-36c1-4f58-9a58-496163a0cf20,480f7be0-ef7f-4001-89e8-6908a5503edb/drives?$select=id,name

Get the Video ID

Once you get all the ids you need, you need to list all the elements inside the library doing the following request, more information about it can be found here

GET sites/{site-id}/drive/{drive-id}/items/root/children

Example: In this example I’m listing all the files in the library root folder and listing the ID and the name of the file.

https://graph.microsoft.com/v1.0/sites/handsonsp.sharepoint.com,89e9f807-36c1-4f58-9a58-496163a0cf20,480f7be0-ef7f-4001-89e8-6908a5503edb/drives/b!B_jpicE2WE-aWElhY6DPIOB7D0h_7wFAiehpCKVQPtttsqxJFrSxRLN8YzWVdyOX/root/children?$select=id,name

Get the thumbnail

Once you get the 3 main IDs you just need to request the preview thumbnail for the file using the following request, more information about it can be found here

GET /sites/{site-id}/drive/items/{item-id}/thumbnails

Example:You will get a JSON object with 3 resolutions for the video thumbnail

https://graph.microsoft.com/v1.0/drives/b!B_jpicE2WE-aWElhY6DPIOB7D0h_7wFAiehpCKVQPtttsqxJFrSxRLN8YzWVdyOX/items/01HSSATH2C7TPHBF5JIRCIHQMWUHIO4GLS/thumbnails

Logo vector created by rawpixel.com – www.freepik.com


3 Responses to “Get video thumbnails from SharePoint using Microsoft Graph”

  1. Jennifer Hidalgo

    March 26, 2020

    Can you do this with stream?

    Reply
    • João Ferreira

      March 26, 2020

      Hi Jennifer,

      It’s not possible to it for now with Stream as it doesn’t have yet a public api.

      Have a nice day 🙂

      Reply
  2. John Witts

    August 24, 2020

    This article was very knowledgeable and affective .after read this article i know about the SharePoint Online has a service to generate and return links to media thumbnails stored in the libraries, It works great for a lot of formats but mp4 videos are no longer supported.This article describes an alternative process to retrieve the thumbnails for the videos you have stored in the libraries using Microsoft Graph.

    Reply

Leave a Reply


I've been working with Microsoft Technologies over the last ten years, mainly focused on creating collaboration and productivity solutions that drive the adoption of Microsoft Modern Workplace.

%d bloggers like this: