Jump to content

ItemsService : /Users/{UserId}/Items with parameter AnyProviderIdEquals


NoEmbyNoFun

Recommended Posts

NoEmbyNoFun

Hello all

I would like to get the information about exactly one movie using the API /Users/{UserId}/Items, using Powershell 5.1 on Windows 10.

Authentication as a user works fine.
Searching directly for the title works fine and returns two items.

# Code:
$mu = 'http://myembyserver:8096/users/' + $uid + '/items?SearchTerm="Southpaw"&Recursive=true&api_key=' + $apikey
Invoke-WebRequest -Uri $mu -Method Get -ContentType "application/json"

# Result:
StatusCode        : 200
StatusDescription : OK
Content           : {"Items":[{"Name":"Southpaw","ServerId":"721f2a80d300464984d9a0e141800e84","Id":"30969","RunTimeTic
                    ks":74554990000,"IsFolder":false,"Type":"Movie","UserData":{"PlaybackPositionTicks":0,"PlayCount":0
                    ,"...

However, when I use the parameter AnyProviderIdEquals 0 items are returned. 

# Code:
$mu = 'http://myembyserver:8096/users/' + $uid + '/items?AnyProviderIdEquals="imdbid.tt1798684"&Recursive=true&api_key=' + $apikey
Invoke-WebRequest -Uri $mu -Method Get -ContentType "application/json"

# Result: 
StatusCode        : 200
StatusDescription : OK
Content           : {"Items":[],"TotalRecordCount":0}
RawContent        : HTTP/1.1 200 OK
                    Access-Control-Allow-Headers: Accept, Accept-Language, Authorization, Cache-Control,
                    Content-Disposition, Content-Encoding, Content-Language, Content-Length, Content-MD5,
                    Content-Rang...

Also with the tmdbid (tmdbid.307081) the result looks the same.
Even if I try to use this parameter in the Swagger UI, I get no result.

What am I doing wrong? 🤔

Many thanks in advance for your advice.

Many greetings,
Dani

Link to comment
Share on other sites

PenkethBoy

not tried but =tt1798684 without the imdbid

Edited by PenkethBoy
Link to comment
Share on other sites

NoEmbyNoFun

Thanks PenkethBoy, 

unfortunately there is no change in the result, no records found.

$mu = 'http://myembyserver:8096/users/' + $uid + '/items?AnyProviderIdEquals="tt1798684"&Recursive=true&api_key=' + $apikey

Invoke-WebRequest -Uri $mu -Method Get -ContentType "application/json"

StatusCode        : 200
StatusDescription : OK
Content           : {"Items":[],"TotalRecordCount":0}
RawContent        : HTTP/1.1 200 OK
                    Access-Control-Allow-Headers: Accept, Accept-Language, Authorization, Cache-Control,
                    Content-Disposition, Content-Encoding, Content-Language, Content-Length, Content-MD5,
                    Content-Rang...

 

Link to comment
Share on other sites

PenkethBoy

ok - never used that end point

but

can you explain what you are trying to achieve in detail and why are you using this endpoint specifically?

Link to comment
Share on other sites

NoEmbyNoFun

Of course, my Emby movie library contains about 1200 movies.
I have an external list of about 800 movies that we have already seen.
This list contains the IMDB ID and TMDB ID of the movies we have seen.
Now, using this list, I want to mark these 800 movies as seen in Emby.

Pseudo-Code for the script:
Read list
Loop over all entries
    Search film in emby
    Update UserData: PlayCount, LastPlayedDate and Played
Ende Loop
 

Link to comment
Share on other sites

roaku

Looking at the api docs, you should be using 'imdb' for your prefix, not 'imdbid'.

Link to comment
Share on other sites

PenkethBoy

off top of my head

i would approach this by

load your list of watched movies

pull back all movies from emby (1200 is not that big)

compare the tmdb id's

then pull the full record for a matched movie (as you cant do a partial update) - update and save

as only needs to be done once

Link to comment
Share on other sites

NoEmbyNoFun

Thanks, that's how it works! 😃

$mu = 'http://myembyserver:8096/users/' + $uid + '/items?AnyProviderIdEquals=imdb.tt1798684&Recursive=true&api_key=' + $apikey
Invoke-WebRequest -Uri $mu -Method Get -ContentType "application/json"

StatusCode        : 200
StatusDescription : OK
Content           : {"Items":[{"Name":"Southpaw","ServerId":"721f2a80d300464984d9a0e141800e84","Id":"30969","RunTimeTicks":7455499000
RawContent        : HTTP/1.1 200 OK
                    Access-Control-Allow-Headers: Accept, Accept-Language, Authorization, Cache-Control, Content-Disposition,
                    Content-Encoding, Content-Language, Content-Length, Content-MD5, Content-Rang...
Forms             : {}
Headers           : {[Access-Control-Allow-Headers, Accept, Accept-Language, Authorization, Cache-Control, Content-Disposition,
                    Content-Encoding, Content-Language, Content-Length, Content-MD5, Content-Range, Content-Type, Date, Host,
                    Transfer-Encoding, Want-Digest, X-MediaBrowser-Token, X-Emby-Token, X-Emby-Client, X-Emby-Client-Version,
                    X-Emby-Device-Id, X-Emby-Device-Name, X-Emby-Authorization], [Access-Control-Allow-Methods, GET, POST, PUT,
                    DELETE, PATCH, OPTIONS], [Access-Control-Allow-Origin, *], [Content-Length, 780]...}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : mshtml.HTMLDocumentClass
RawContentLength  : 780

I don't know why I used imdbid, sorry for that and thanks again for your support. 

  • Like 1
Link to comment
Share on other sites

NoEmbyNoFun
20 minutes ago, PenkethBoy said:

...

pull back all movies from emby (1200 is not that big)

compare the tmdb id's

...

Is there an easy way (a end point) to pull back all movies with one request or do I have to loop over all libraries?

Edited by NoEmbyNoFun
Link to comment
Share on other sites

PenkethBoy

yes \items endpoint will do that with includeitemtype=movie and recursive=true or the one you are using if you need to limit by user - it will pull all movies so you may need to limit by parentid to limit by a library

use swagger to test it - via "API" link at bottom of dashboard page

e.g. http://localhost:8096/emby/Items?Recursive=true&IncludeItemTypes=movie&api_key=<api_key>

 

Might also be time to move to PS 7.1 as latest stable release :)  

Link to comment
Share on other sites

NoEmbyNoFun

Thanks again, good point 👍

If anyone is interested, I can post the script here.

Otherwise the topic can be closed.

Link to comment
Share on other sites

NoEmbyNoFun

Hi nunu22

The script became a bit longer than planned, so I'm happy to make it available here.
The script allows a certain Emby user to mark one or more films as watched, based on TMDB ID or IMDB ID.
This Emby user needs the right to manage the Emby server.
The script requires Powershell, version 5.1, which is automatically included with Windows 10.

To get all items for a specific user, I use the endpoint /Users/{UserId}/Items
Details can also be found in the Swagger UI.

Best regards,
Dani

EmbySet-Watched.ps1

Link to comment
Share on other sites

nunu22

thanks for the sharing  !

i'am not familiar with http stuff and i'am discoevring the emby API & swagger UI    :)

i try to make a script to synchronzied  watched item between 2 servers in bash.

 

regards.

 

Link to comment
Share on other sites

nunu22

Hi,

I not so far from my little script. I can get movie information from a User from 2 servers and identifying items to set to "Played".

i have check  NoEmbyNoFun script and see that there is the entry point :   /Users/$USER/Items/$ID/UserData/

I don't see the swagger information about this (maybe i have missed something)

Never mind, i try to use it to set a movie of a user to Played=true:

The code is in Bash :

    URL=$SERVER_URL"/Users/$USER/Items/$ID/UserData/?api_key=$KEY"

    curl -X POST "$URL" -H  "accept: application/json" -d '{"Played": "true"}'

 

I guess that "UserData" in the URL allows to point directly to a field of the strcuture:

 {
      "Name":
      "ServerId":
      "Id":
      "RunTimeTicks":
      "IsFolder":
      "Type":
      "UserData": {   <=========================== HERE
        "PlaybackPositionTicks": 0,
        "PlayCount": 1,
        "IsFavorite": false,
        "LastPlayedDate":
        "Played": true
      },
      "ImageTags": {
        "Primary":
        "Logo":
        "Thumb":
      },
      "BackdropImageTags": [
      ],
      "MediaType":
    },

 

But i have this error : Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).

I check on the net, but i miss skill on HTTP things :)

If anyone can help ?!

 

regards

 

 

Link to comment
Share on other sites

PenkethBoy

not tested but $used in your url would be like this "dbb929563df645b3b95b2c9fd0b28313"

but you need to also return a "body" with a json payload - Played true will not work

Link to comment
Share on other sites

nunu22

yes $USER  is something like you have describe.

 

-d '{"Played": "true"}'  won't be considered like a json payload ?

Link to comment
Share on other sites

PenkethBoy

emby does not allow partial updates

you need to return the full json as the body

Link to comment
Share on other sites

nunu22

Hi,

i have still error 404.

it seems that 404 means that communication is OK with the server but the ressource is not find.

I use the entry point : /Users/$USERID/Items/$ITEMID/?api_key=$KEY , but in swagger, i don't see this ressource for POST (only for GET)

If i use the URL for a GET it works (i get the json information of the item).

But for the POST i have 404 error (and adding -d option), i get in server logs these 2 lines:

2021-03-30 16:54:41.290 Info Server: http/1.1 POST http://xxxxxxxxxxxxxxxxx//Users/a3bf1dbe2f6743c8a65fabbed9ee2537/Items/489/. UserAgent: curl/7.54.0
2021-03-30 16:54:41.290 Info Server: http/1.1 Response 404 to 90.32.21.126. Time: 0ms. http://xxxxxxxxxxxxxxxxxxx//Users/a3bf1dbe2f6743c8a65fabbed9ee2537/Items/489/

What kind of error is generated if a json data to send during a POST is not correct ? could it be 404 ?

 

regards

 

Link to comment
Share on other sites

NoEmbyNoFun

Hi nunu22

Some experiences I've made with my script.
I don't know what the exact syntax is in Bash, but would like to show some important points using Powershell code.

Use the endpoint /Users/$USERID/Items/$ITEMID to get the item you want to update.
This seems to work.

Extract the userdata from the item.

Powershell Code: $ud = $ITEMID.UserData

Update the userdata as you like.

Powershell Code: $ud.Played = $true

Use the endpoint /Users/$USERID/Items/$ITEMID/UserData to update the user data of the item.
The body must only contain the user data, not the whole item.

Powershell Code: Invoke-Webrequest -uri "/Users/$USERID/Items/$ITEMID/UserData?api_key=$KEY" -Method POST -Body ( $ud | ConvertTo-Json ) -ContentType "application/json; charset=utf-8"

The relevant part is "POST -Body ( $ud | ConvertTo-Json )". 
As you can see only the user data $ud is converted into JSON, not the whole $ITEM.

Hope it's of some use.

On which platform should your script work?

Greetings, 
Dani

 

Link to comment
Share on other sites

nunu22

thanks for your answer !

i have read your script and by this way i had discover the endpoint /Users/$USERID/Items/$ITEMID/UserData  that seems not in swagger.

I run my script on a synology NAS.

the form of  the data that i try to post : {   "PlaybackPositionTicks": 0,   "PlayCount": 0,   "IsFavorite": false,   "Played": true }

i don't know if the format is OK ?

 

 

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...