Patrick Lamber

Patrick Lamber - Mar 6, 2017 - Follow          
Technical consultant and Office Server and Services MVP.

Accessing the Office 365 Video API through PowerShell

The post "Accessing the Office 365 Video API through PowerShell" is a post of a post series. Find below all posts associated to this post series.
by Patrick Lamber on Mar 6, 2017
Filed under: Governance Office 365 Video Scripts Office 365
Share it:

The REST Video API is used to discover and interact with videos in the Office 365 Video service. You can find the official documentation here. The API allows you to interact with the Video Channels and Videos and perform all operations necessary to build your own Video portal interface if necessary. As an IT administrator you might want to build your own governance and discover system to interact with the Video portal assets. This blog post shows how you could get started in accessing Video information using the REST Video API and PowerShell. This will be accomplished with the help of the latest SharePoint Online SDK.

The examples presented in this blog series will use the latest SharePoint Online SDK. You need to download the components to your machine. This post explains how to get the necessary DLLs.

Authenticate to Office 365 Video and execute REST calls

This snippet is going to be used as basic snippet for all examples following. It is going to authenticate with SharePoint Online using the SharePoint Online SDK. I created a simple function that calls the REST endpoint and returns the results in a variable. Afterwards, the variable can be used to traverse the results.

The example below can be used for GET operations only and does not handle exceptions. Please extend your code to have better exception management.
# your path to the net45 DLLs you downloaded

$pathToCSOM = "H:\Development\net45"
$tenantName = "yourTenantName"
$videoPortalUrl = "https://$($tenantName).sharepoint.com/portals/hub/_api/VideoService/"

# Load the necessary SDK DLLs

[Reflection.Assembly]::LoadFrom("$($pathToCSOM)\Microsoft.SharePoint.Client.dll")
[Reflection.Assembly]::LoadFrom("$($pathToCSOM)\Microsoft.SharePoint.Client.Runtime.dll")

# Authenticate to SharePoint Online

$cred = Get-Credential
$cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($cred.UserName, $cred.Password);

# function used to get the rest contents in JSON format

Function Get-RestContents ($url, $cred) {
    $r = [System.Net.WebRequest]::Create($url);
    $r.Credentials = $cred
    $r.Accept = "application/json;odata=verbose"
    $r.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f")

    $res = $r.GetResponse()
    $stream = New-Object System.IO.StreamReader $res.GetResponseStream()
    $results = $stream.ReadToEnd()
    $stream.Dispose()
    return ($results | ConvertFrom-Json).d
}
by Patrick Lamber on Mar 6, 2017
Filed under: Governance Office 365 Video Scripts Office 365
Share it:
The post "Accessing the Office 365 Video API through PowerShell" is a post of a post series. Find below all posts associated to this post series.