ScreenCloud API Takeover with PowerShell

1 Feb

With the recent release of the ScreenCloud API I thought I would have a quick play to see what could be done.

In short, you can push out content to any screen pragmatically as you would expect but as users tend to do this via the GUI I don’t currently have much need. The option that really stood out was the takeover to push out content to any screen(s) and then cancel the takeover to have it resume its original playlist/schedule etc.

I created a YouTube app which ran the liveĀ Sky Newsfeed on YouTube. I then wrote a bit of PowerShell to grab all the screen ID’s for the team and then set them all to run the SkyNews feed, and then 30 seconds later revertĀ back to their original content.

#Credentials etc.
$uri = "https://signage-api.screen.cloud/api/v1/"

$user= "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
$pass = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

$pair = "${user}:${pass}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$headers = @{ Authorization = $basicAuthValue }

#ScreenCloud Team ID
$teamid = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

#Youtube of SkyNews
$JSON = @'
{
"@url":"",
"content_id":"-Kxxxxxxxxxxxxxxxxx",
 "mime_type":"application/x-sc-app"
}
'@

#Call to get the screen ID's
$screenlist = $uri + "teams/" + $teamid + "/screens"

#Create the screen list
$result = Invoke-WebRequest -headers $headers -uri $screenlist -Method Get | ConvertFrom-Json

#Takeover each screen
foreach ($screenid in $result.id) {
  write-host $screenid
  $tempuri = $uri + "teams/" + $teamid + "/screens/" + $screenid + "/takeover"
  Invoke-WebRequest -body $JSON -uri $tempuri -Headers $headers -Method Put -ContentType "application/json"
}

#Pause/Wait
start-sleep -s 30

#Delete takeover for each screen
foreach ($screenid in $result.id) {
  write-host $screenid
  $tempuri = $uri + "teams/" + $teamid + "/screens/" + $screenid + "/takeover"
  Invoke-WebRequest -body $JSON -uri $tempuri -Headers $headers -Method Delete -ContentType "application/json"
}