Jump to content

Playlist creation [with powershell]


ginjaninja

Recommended Posts

ginjaninja

swagger tells me to create a playlist i post to

http://192.168.4.162:8096/emby/Playlists?Name=RPE3&&Ids=320966&mediaType=Video&Api_key=b5a23a2313e24b30be064ad12d29983c

which works in swagger as

curl -X POST "http://localhost:8096/emby/Playlists?Name=rpe3&Ids=320966&MediaType=Video&api_key=ab8b235fb758488c8bd4c31e4c02ffdc" -H "accept: application/json" 

there is no body shown in swagger, so i am not posting any body in powershell.

 

so in powershell i have so far

$Headers = @{"Authorization"="Emby Client=`"clientname`", Device=`"deviceName`", DeviceId=`"DeviceId`", Version=`"AppVersion`""}
$apiresult = Invoke-WebRequest -Uri $ApiUrl -Method POST -ContentType "application/json" -Headers $Headers
 
expecting for $apiresult to be set to something like {
"Id": "321037",
"Name": "RPE3"
}

as per swagger 

 

 

except i get" Object reference not set to an instance of an object."

2020-05-18 22:04:07.497 Info HttpServer: HTTP POST http://192.168.4.162:8096/emby/Playlists?Name=RPE3&&Ids=320966&mediaType=Video&Api_key=b5a23a2313e24b30be064ad12d29983c. UserAgent: Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.18363; en-GB) PowerShell/7.0.1
2020-05-18 22:04:07.498 Error HttpServer: Error processing request
	*** Error Report ***
	Version: 4.5.0.11
	Command line: C:\Users\Nicholas Bird\AppData\Roaming\Emby-Server\system\EmbyServer.dll C:\Users\Nicholas Bird\AppData\Roaming\Emby-Server\system\EmbyServer.dll -noautorunwebapp
	Operating system: Microsoft Windows NT 6.2.9200.0
	64-Bit OS: True
	64-Bit Process: True
	User Interactive: True
	Runtime: file:///C:/Users/Nicholas Bird/AppData/Roaming/Emby-Server/system/System.Private.CoreLib.dll
	System.Environment.Version: 3.1.4
	Processor count: 12
	Program data path: C:\Users\Nicholas Bird\AppData\Roaming\Emby-Server\programdata
	Application directory: C:\Users\Nicholas Bird\AppData\Roaming\Emby-Server\system
	System.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object.
	   at MediaBrowser.Api.PlaylistService.Post(CreatePlaylist request)
	   at Emby.Server.Implementations.Services.ServiceController.GetTaskResult(Task task)
	   at Emby.Server.Implementations.Services.ServiceHandler.ProcessRequestAsync(HttpListenerHost appHost, IRequest httpReq, IResponse httpRes, RestPath restPath, String responseContentType, CancellationToken cancellationToken)
	   at Emby.Server.Implementations.HttpServer.HttpListenerHost.RequestHandler(IRequest httpReq, ReadOnlyMemory`1 urlString, ReadOnlyMemory`1 localPath, CancellationToken cancellationToken)
	Source: Emby.Api
	TargetSite: Void MoveNext()
	
2020-05-18 22:04:07.498 Info HttpServer: HTTP Response 500 to 192.168.4.162. Time: 1ms. http://192.168.4.162:8096/emby/Playlists?Name=RPE3&&Ids=320966&mediaType=Video&Api_key=b5a23a2313e24b30be064ad12d29983c

any ideas as to what i am doing wrong please

 

this is the first time i am posting in powershell..previously i have been 'getting' without issue.

 

 

Link to comment
Share on other sites

Can you try creating one in Chrome, and then watching the network tab of the browser debug console. You can see the request url and body used by the web app. How does yours compare?

Link to comment
Share on other sites

PenkethBoy

You are confusing things - there is no body to post and swagger shows you the result what it returns

 

to create an Audio Playlist - same for video just change the MediaType in the url

 

$An.Name - is the name of the playlist

$IDS - is a comma separated list of item id's for the song or video - or separate the Id's with %2C which is a , but used in url's

 

$MediaUrl = $embyServerUrl + "/emby/playlists?Name=" + $AN.Name + "&Ids="+ $IDS + "&MediaType=Audio&api_key=" + $User.AccessToken
 
$Result = Invoke-Webrequest -uri $MediaUrl -Method POST
 
$Result.StatusCode will be 204
Link to comment
Share on other sites

ginjaninja

Can you try creating one in Chrome, and then watching the network tab of the browser debug console. You can see the request url and body used by the web app. How does yours compare?

 

thanks thats a useful trick i didnt know that existed. you can even copy the request as powershell.

Invoke-WebRequest -Uri "http://localhost:8096/emby/Playlists?Name=test4&Ids=279235&UserId=6cc6d0fa039849af8147592f5da46188" `
-Method "POST" `
-Headers @{
"accept"="application/json"
  "X-Emby-Client-Version"="4.5.0.11"
  "X-Emby-Client"="Emby Web"
  "X-Emby-Token"="ab8b235fb758488c8bd4c31e4c02ffdc"
  "X-Emby-Device-Id"="TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzcyLjAuMzYyNi4xMjEgU2FmYXJpLzUzNy4zNnwxNTUyNzM5MTY1MzY5"
  "User-Agent"="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"
  "X-Emby-Device-Name"="Chrome"
  "Origin"="http://localhost:8096"
  "Sec-Fetch-Site"="same-origin"
  "Sec-Fetch-Mode"="cors"
  "Sec-Fetch-Dest"="empty"
  "Referer"="http://localhost:8096/web/index.html"
  "Accept-Encoding"="gzip, deflate, br"
  "Accept-Language"="en-GB,en-US;q=0.9,en;q=0.8"
  "Cookie"="tautulli_token_6ee8b6f796244431886d680c45a7139b=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjozOTg2NTMsInVzZXIiOiJnaW5qYW5pbmphIiwiZXhwIjoxNTkwNjA4OTAxLCJ1c2VyX2dyb3VwIjoiYWRtaW4ifQ.xtQdQA9cBYtWQNYj1dTeyMjtd7fJ2oHGfCQu8S-Gd0c"
}

 

You are confusing things - there is no body to post and swagger shows you the result what it returns

 

to create an Audio Playlist - same for video just change the MediaType in the url

 

$An.Name - is the name of the playlist

$IDS - is a comma separated list of item id's for the song or video - or separate the Id's with %2C which is a , but used in url's

 

$MediaUrl = $embyServerUrl + "/emby/playlists?Name=" + $AN.Name + "&Ids="+ $IDS + "&MediaType=Audio&api_key=" + $User.AccessToken
 
$Result = Invoke-Webrequest -uri $MediaUrl -Method POST
 
$Result.StatusCode will be 204

 

 

thanks for clarification.

 

so i successfully posted without headers and using an apikey (worked as well as user token) but i had to provide userid as in the chrome output, like so

$apiurl = "http://localhost:8096/emby/Playlists?Name=rpe4&Ids=320966&MediaType=Video&UserId=6cc6d0fa039849af8147592f5da46188&api_key=ab8b235fb758488c8bd4c31e4c02ffdc"

is the conclusion that "userid is a requirement for this api endpoint" the wrong one?

or is just because i am using an generic apikey the reason that i have to supply userid? or something else :-).

Link to comment
Share on other sites

PenkethBoy

If you authenticate as a user and use the access token that gets returned from emby then you dont need the generic key at all - i have never used one as a bit pointless in 99% of cases

 

you use that returned token as you api_key

 

the example code i gave you a few weeks back showed you how to authenticate and get the token

 

I dont need to provide the userid when creating, updating playlists - as playlists are not user specific - they are general so everyone can see and amend them in emby

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