Jump to content

api call to create/add new library (eg. via curl post)?


Recommended Posts

Posted (edited)

Hi!  I find myself having to re-create libraries quite often (I frequently re-image my server, for instance), and it's a bit painful having to add libraries manually each time.  I found the (swagger) docs for api calls that I could make via (eg.) curl here (localhost):

 

  http://localhost:8096/swagger-ui/index.html

 

but it doesn't seem to include a call to create/add a new library.  Is that possible?  I'm hoping for something like:

 

  curl -H "token:abcdef" -X POST -F 'name=videos' -F 'real_time_monitoring=true' http://localhost:8096/CreateLibrary

 

but obviously happy with anything that allows me to create libraries programmatically!

 

Thanks,

 

Mike

Edited by masp
Posted (edited)

Thanks!  Can you give me a clue as to which method to look for?  Best I can guess is maybe addVirtualFolder (?).

 

Update: in the meantime I'm trying to authenticate: following the swagger docs + some other hints, it looks like this should work:

 

 

curl -X POST -d "{Username:\"mike\", Password:\"adc83b19e793491b1c6ea0fd8b46cd9f32e592fc\",PasswordMd5=\"68b329da9893e34099c7d8ad5cb9c940\"}" "http://127.0.0.1:8096/Users/AuthenticateByName?format=json"

 

(where the passwords are hashes of the empty string, since I don't have a password) but it errors out with:

 

 

{"ResponseStatus":{"ErrorCode":"ArgumentNullException","Message":"Value cannot be null.\nParameter name: username","Errors":[{"ErrorCode":"ArgumentNullException","FieldName":"username","Message":"Value cannot be null.\n"}]}} 

 

I've tried using lowercase (username) but no change.  Is there a simple fix, to save my hours of experimentation? :)

 

Thanks,

 

Mike

Edited by masp
Posted (edited)

I've looked at all the examples I can find, and fixed my broken md5/sha1 hashes, but I still have the same problem.  This is the best I can come up with: [edited to quote the json keys]

 

 

curl -X POST -H 'Content-Type: application/json' -H 'Authorization: MediaBrowser Client="testingembyclient", Device="testingembydevice", DeviceId="6c37664af595bec4424bad444f842af9e0916ab1", Version="1.0.0", UserId="4b023a683f404b63a5174f859f42bd06"' -d "{[\"Username\":\"mike\", \"password\":\"da39a3ee5e6b4b0d3255bfef95601890afd80709\",\"passwordMd5\"=\"d41d8cd98f00b204e9800998ecf8427e\"]}" "http://127.0.0.1:8096/Users/AuthenticateByName?format=json"

 

but response is:

 

 

{"ResponseStatus":{"ErrorCode":"ArgumentNullException","Message":"Value cannot be null.\nParameter name: username","Errors":[{"ErrorCode":"ArgumentNullException","FieldName":"username","Message":"Value cannot be null.\n"}]}}

 

Any pointers will be gratefully received!  I was very excited when I found emby, partly because it has such a full API, but it's frustratingly hard to get it to work!  I must be doing something stupid: if anyone can point it out to me that would be great!

 

Mike

Edited by masp
Posted

Looks like a syntax error in your json (= instead of :) but not sure if that is the exact problem here.

Posted (edited)

Rats!  Thanks!  I also appended "format=json" to the url.  Unfortunately neither fix gets me to a working query :(

curl -X POST -H 'Content-Type: application/json' -H 'Authorization: MediaBrowser Client="testingembyclient", Device="testingembydevice", DeviceId="6c37664af595bec4424bad444f842af9e0916ab1", Version="1.0.0", UserId="4b023a683f404b63a5174f859f42bd06"' --data '{["username":"mike", "password":"da39a3ee5e6b4b0d3255bfef95601890afd80709","passwordMd5":"d41d8cd98f00b204e9800998ecf8427e"]}' "http://127.0.0.1:8096/Users/AuthenticateByName?format=json"
Edited by masp
Posted

Thanks, that did the trick!   I just had to remove the outer list [] in the post data (could have sworn I'd tried it both ways!!). Thanks very much for the tip: those devtools are really useful!! :)

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