Get Stream video viewers and views

Within Stream (on SharePoint) it is possible upload, share and manage videos. In this article I will show you how to retrieve analytics via a Power Automate flow for such type of video files.

Inspiration

This question from Tracy_ngu:

I would like to get the views of my videos (as per highlighted below) and add a row into Excel Online. As I understand, the only way is by sending a HTTP request to Sharepoint.

Power Users Community thread: What is the API to get Stream on Sharepoint Video Analytics?.

Stream Analytics

Stream used to be a separate product. However, the new Stream (on SharePoint) hosts and manages the video files on SharePoint Online. The additional benefit of using SharePoint Online is that you are able to use the out of the box analytics features as well.

Below is an example of the File Statistics interface of a single file.

viewers_views

Get itemAnalytics

In our scenario the goal is to retrieve those details via a Power Automate flow. We can use the Get itemAnalytics method from the Graph API.

In a Send an HTTP request to SharePoint action it is possible to use SharePoint REST operations via the Microsoft Graph REST API. As outlined in that document sites and lists are supported endpoints.

With the Get itemAnalytics method you can specify if you want to retrieve allTime analytics or just for the lastSevenDays. I am using the allTime option.

That method will return an access property which contains nested actionCount (Views) and actorCount (Viewers) properties.

Flow Setup

This sample assumes you have already retrieved the siteid, listid and uniqueid of the video file. Have a look at my related articles to find out how to retrieve those values.

streamvideoanalytics

1. Add a Manually trigger a flow action.

manuallytriggeraflow

2. Add a Initialize variable action.

siteid_variable

a. Provide a Name, in this example SiteId
b. Select a Type, String
c. Provide a Value, in this case contoso.sharepoint.com,cb12be95-3f7d-418a-bc6b-a998a72090fd,4dd1a58b-7dc0-4133-9718-3a36d1d79efb

3. Add a second Initialize variable action.

listid_variable

a. Provide a Name, in this example ListId
b. Select a Type, String
c. Provide a Value, in this case 99a3c302-8818-46fb-a1df-8d89d9210200

4. Add a third Initialize variable action.

uniqueid_variable

a. Provide a Name, in this example UniqueId
b. Select a Type, String
c. Provide a Value, in this case dc14e005-c044-4841-8e38-4c11fd51429a

5. Add a Send an HTTP request to SharePoint action.

alltime_actorandactioncount

a. Select your preferred site in the Site Address
b. Use the GET method
c. Use the URI from the code snippet below

d. Use the Headers from the code snippet below

The test results

When you run this flow you should see the same counts in the outputs.

testresult_actoractioncounts

Happy testing!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.