Jump to content

Emby API Watched Status


Recommended Posts


Hello everyone,

iam trying to create a script which will allow me to backup the watched statuses of multiple users in my household. I have the following code to get the movies list from my current installation. The issue is when i query the movie list that is returned, i do not see the watched status of the movies.


Can anyone please point me in the right direction.




$embyServerUrl = "http://localhost:8096"
$embyUsername = "dummy"
$embyPassword = "xxxxxx"

$embyClientName = "PowerShellScript"
$embyDeviceName = "PowerShellScriptEpisodeFiller"
$embyDeviceId = "1"
$embyApplicationVersion = "1.0.0";

$authUrl = "{0}/Users/AuthenticateByName?format=json" -f $embyServerUrl

Function Get-StringHash([string] $String,$HashName = "MD5")
    $StringBuilder = New-Object System.Text.StringBuilder

function Get-EmbyAccessToken {
    param ($username, $password)
    $authUrl = "{0}/Users/AuthenticateByName?format=json" -f $embyServerUrl
    $sha1Pass = Get-StringHash -String $password -HashName "SHA1"
    $md5Pass = Get-StringHash -String $password
    $postParams = (@{Username="$username";password="$sha1Pass";passwordMd5="$md5Pass"} | ConvertTo-Json)
    $headers = @{"Authorization"="MediaBrowser Client=`"$embyClientName`", Device=`"$embyDeviceName`", DeviceId=`"$embyDeviceId`", Version=`"$embyApplicationVersion`""}

    Write-Verbose ("authUrl={0},Username={1},sha1Pass={2},md5Pass={3},params={4}" -f $authUrl, $Username,$sha1Pass,$md5Pass,$postParams)
    return (Invoke-WebRequest -Uri $authUrl -Method POST -Body $postParams -ContentType "application/json" -Headers $headers)

function Get-EmbyMovieList {
    param ($AccessToken)

    $url = "{0}/Items/UserData?format=json&recursive=true&IncludeItemTypes=Movie" -f $embyServerUrl
    $embyHeaderWithAccessToken = @{"X-MediaBrowser-Token"=$user.AccessToken}

    Write-Verbose ("authUrl={0},Header={1}" -f $url, $embyHeaderWithAccessToken)
    return (Invoke-WebRequest -Uri $url -Method GET -ContentType "application/json" -Headers $embyHeaderWithAccessToken)


function Write-Feedback()
        [string]$BackgroundColor = "Yellow",
        [string]$ForegroundColor = "Black"

    Write-Host -BackgroundColor $BackgroundColor -ForegroundColor $ForegroundColor $msg;
    $msg | Out-File "c:\Users\kodi-client\Desktop\movielist.json"; # <<< or add a param to location

$authResult = Get-EmbyAccessToken -Username $embyUsername -Password $embyPassword
$user = $authResult.Content | ConvertFrom-Json
$userAccessToken = $user.AccessToken

$movieList = Get-EmbyMovieList -AccessToken $userAccessToken

Write-Feedback $movieList
#Write-Host ($movieList)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...