Oracle 83 Posted October 13, 2022 Posted October 13, 2022 Hi, all. So, I've been just slowing chipping away at this PowerShell script I run every night to sync my server with some other drives and want to make an API request to scan the Emby library and call two other requests as well (Timelord Plugins). Has anyone does this that has some code they'd be willing to share (privately or publicly) as examples? Here is my barebones script, without any of my server's info in there. Thanks! server_sync (1).ps1
Happy2Play 9140 Posted October 13, 2022 Posted October 13, 2022 Don't know power shell but I just use the api curl request in bat file for simple tasks on demand. use parentid for specific library scan REM Specific library scan C:\Windows\System32\curl.exe -X POST "http://localhost:8096/emby/Items/390537/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default&ReplaceAllImages=false&ReplaceAllMetadata=false?api_key=YOURAPIKEY" -d "" REM Full Scan C:\Windows\System32\curl.exe -X POST "http://localhost:8096/emby/ScheduledTasks/Running/6330ee8fb4a957f33981f89aa78b030f?api_key=YOURAPIKEY" -d "" REM TimeLord Movie-TV C:\Windows\System32\curl.exe -X POST "http://localhost:8096/emby/ScheduledTasks/Running/b95991ed8b0d75310172647aa4505a84?api_key=YOURAPIKEY" -d "" C:\Windows\System32\curl.exe -X POST "http://localhost:8096/emby/ScheduledTasks/Running/a83932aa7d62326d7624ceb39611ca6b?api_key=YOURAPIKEY" -d "" 1
Oracle 83 Posted October 13, 2022 Author Posted October 13, 2022 Thanks @Happy2Play! I appreciate these, this is really helpful! However, I've been having some difficulty in getting these to run. I can get them to work on Swagger no issue. I suppose I need to learn how to authenticate and invoke a web request through a text script. 1
Happy2Play 9140 Posted October 13, 2022 Posted October 13, 2022 Not sure of your issue as I have a bat file with this for updates but applies to all calls. C:\Windows\System32\curl.exe -X POST "http://192.168.151.16:8096/emby/ScheduledTasks/Running/1cc2f60a05befec8b1532ac44630a00f?api_key=yourapikey" -d "" C:\Windows\System32\curl.exe -X POST "http://192.168.151.16:8096/emby/ScheduledTasks/Running/c27fda37dfb6e39be141191aaa1c3060?api_key=yourapikey" -d "" 2022-10-13 16:10:14.979 Info Server: http/1.1 POST http://192.168.151.16:8096/emby/ScheduledTasks/Running/1cc2f60a05befec8b1532ac44630a00f. UserAgent: curl/7.84.0 2022-10-13 16:10:14.981 Debug AuthenticationRepository: GetCapabilities id: 48 2022-10-13 16:10:14.981 Info Server: http/1.1 Response 204 to 192.168.151.59. Time: 2ms. http://192.168.151.16:8096/emby/ScheduledTasks/Running/1cc2f60a05befec8b1532ac44630a00f 2022-10-13 16:10:14.981 Debug TaskManager: Executing Check for application updates 2022-10-13 16:10:14.982 Info HttpClient: GET https://api.github.com/repos/MediaBrowser/Emby.Releases/releases 2022-10-13 16:10:15.008 Info Server: http/1.1 POST http://192.168.151.16:8096/emby/ScheduledTasks/Running/c27fda37dfb6e39be141191aaa1c3060. UserAgent: curl/7.84.0 2022-10-13 16:10:15.010 Info Server: http/1.1 Response 204 to 192.168.151.59. Time: 2ms. http://192.168.151.16:8096/emby/ScheduledTasks/Running/c27fda37dfb6e39be141191aaa1c3060 2022-10-13 16:10:15.010 Debug TaskManager: Executing Check for plugin updates 2022-10-13 16:10:15.010 Info HttpClient: GET https://www.mb3admin.com/admin/service/EmbyPackages.json 2022-10-13 16:10:16.071 Debug TaskManager: Check for plugin updates Completed after 0 minute(s) and 1 seconds 2022-10-13 16:10:17.378 Debug App: No application update available. 2022-10-13 16:10:17.378 Debug TaskManager: Check for application updates Completed after 0 minute(s) and 2 seconds
Happy2Play 9140 Posted October 13, 2022 Posted October 13, 2022 @Arly (Sprinkles) A guess, did you generate your own api key to use? Settings-API keys
chef 3799 Posted October 14, 2022 Posted October 14, 2022 2 hours ago, Happy2Play said: @Arly (Sprinkles) A guess, did you generate your own api key to use? Settings-API keys I was just going to mention that might be the issue. That's nice work there by the way!
rbjtech 4811 Posted October 14, 2022 Posted October 14, 2022 (edited) If using a http request (ie not https) you may also need the script running on the same machine for this to work (ie localhost) - and use localhost, not the IP. This is due to limitations on cross scripting - you get the same limitation if you try and use the API directly via swagger from a different host. Edited October 14, 2022 by rbjtech
Oracle 83 Posted October 14, 2022 Author Posted October 14, 2022 Yeah, I did generate an API. I ended up just creating a batch file (which works great!) and adjusting it for my specific needs, and then calling that batch script from within my sync script in PowerShell! I'm going to keep working on seeing how I can use Emby's API in PowerShell. Postman might be able to help. On another note, now that I've gone down a rabbit hole here of API stuff (Seriously, up until 3am on this stuff), what are some examples of things that you guys use the API for? I know that @Happy2Play mentioned he uses a handful of scripts.
chef 3799 Posted October 14, 2022 Posted October 14, 2022 Controlling sessions Session events (playback etc.) User management Images Provider data Streaming Item metadata Very powerful stuff...
hnorgaar 1 Posted October 18, 2022 Posted October 18, 2022 On 14/10/2022 at 02:06, Happy2Play said: Don't know power shell but I just use the api curl request in bat file for simple tasks on demand. use parentid for specific library scan REM Specific library scan C:\Windows\System32\curl.exe -X POST "http://localhost:8096/emby/Items/390537/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default&ReplaceAllImages=false&ReplaceAllMetadata=false?api_key=YOURAPIKEY" -d "" REM Full Scan C:\Windows\System32\curl.exe -X POST "http://localhost:8096/emby/ScheduledTasks/Running/6330ee8fb4a957f33981f89aa78b030f?api_key=YOURAPIKEY" -d "" REM TimeLord Movie-TV C:\Windows\System32\curl.exe -X POST "http://localhost:8096/emby/ScheduledTasks/Running/b95991ed8b0d75310172647aa4505a84?api_key=YOURAPIKEY" -d "" C:\Windows\System32\curl.exe -X POST "http://localhost:8096/emby/ScheduledTasks/Running/a83932aa7d62326d7624ceb39611ca6b?api_key=YOURAPIKEY" -d "" How would i find the task number for library scan on my system or is it the same number for everybody? Thx
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now