Jump to content

Recommended Posts

Posted

I am trying to build an script to delete an item, but I can't seem to figure out how to provide the correct itemid for the delete call.

 

When I do a call for the users items I get back a list of items to iterate through, but I can't figure out which ID i need to call the delete call too.

 

When I try to run the curl command it keeps returning "Object reference not set to an instance of an object."

 

Can anyone tell me what I am doing wrong and what I should be passing for ITEM_ID?

 

Here is what I am trying to call for the delete

curl -X DELETE "http://server.name:8096/emby/Items/ITEM_ID?api_key=YYYYYYYYYYYYYYYYYYYY"-H  "accept: */*"

 

 

Here is a example of what I get in the item list

    {
      "UserData": {
        "IsFavorite": false, 
        "Played": true, 
        "LastPlayedDate": "2019-08-07T02:55:33.0000000+00:00", 
        "PlaybackPositionTicks": 0, 
        "Key": "XXXXXXX-aaf2-99e5-2c12-18ed90911ae9", 
        "PlayCount": 4
      }, 
      "Name": "Video Name", 
      "IsFolder": false, 
      "MediaType": "Video", 
      "ImageTags": {
        "Primary": "XXXXXXf2bc3c4560ce7c13d2d3d3b9"
      }, 
      "RunTimeTicks": 27404580864, 
      "ServerId": "XXXXXXXXX4c18a82261296b1ce86b", 
      "Type": "Video", 
      "Id": "14", 
      "BackdropImageTags": []
    }, 
Posted

Hi.  Can we back up a second and have you tell us what you are really trying to accomplish overall?

 

Then we may be able to offer advice on how to do it.

 

Thanks.

Posted

I am working on a script to delete watched content after meeting a set of rules (eg, by user, age, last play time,...)

 

Right now I just have a basic call to:

server_url + '/emby/Users/' + user_key  + '/Items?Recursive=true&IsPlayed=true&api_key=' + auth_key

 

I then iterate through the results and extract data from each item.  This part is working fine.

 

Once I am done I want to them do an API call for emby to delete the item and file.  This is the part I can't seem to get working

Posted

Okay, so you have an item object for each one you want to delete. It has an Id property.  That is the Id you will use in the delete call.

Posted (edited)

That's what I have tried but it is still giving me the "Object reference not set to an instance of an object." error.

In the example item object I provided it has an ID of 14.  So I built the following curl command which I got the format from the swagger interface.  But it is still returning that error.  I tried checking the logs for emby but there isn't anything there
 


curl -X DELETE "http://server.name:8096/emby/Items/14?api_key=YYYYYYYYYYYYYY"-H  "accept: */*"


In case it makes any difference I am running through a docker image.  But I have confirmed that through the web interface I am able to delete the file.

 

Edited by jpc82
Posted

Found this in the log.

2019-09-13 16:57:18.146 Info HttpServer: HTTP DELETE http://server.name:8096/emby/Items/14. UserAgent: curl/7.58.0
2019-09-13 16:57:18.147 Error HttpServer: Error processing request
	*** Error Report ***
	Version: 4.1.1.0
	Command line: /system/EmbyServer.dll -programdata /config -ffdetect /bin/ffdetect -ffmpeg /bin/ffmpeg -ffprobe /bin/ffprobe -restartexitcode 3
	Operating system: Unix 5.2.11.50211
	64-Bit OS: True
	64-Bit Process: True
	User Interactive: True
	Runtime: file:///system/System.Private.CoreLib.dll
	Processor count: 16
	Program data path: /config
	Application directory: /system
	System.NullReferenceException: System.NullReferenceException: Object reference not set to an instance of an object.
	   at MediaBrowser.Controller.Entities.BaseItem.IsAuthorizedToDelete(User user, Folder[] collectionFolders)
	   at MediaBrowser.Api.Library.LibraryService.Delete(DeleteItems request)
	   at Emby.Server.Implementations.Services.ServiceExecGeneral.<>c__DisplayClass5_0.<CreateExecFn>b__0(Object service, Object request)
	   at Emby.Server.Implementations.Services.ServiceExecGeneral.Execute(Type serviceType, IRequest request, Object instance, Object requestDto, String requestName)
	   at Emby.Server.Implementations.Services.ServiceController.Execute(HttpListenerHost appHost, Object requestDto, IRequest req)
	   at Emby.Server.Implementations.Services.ServiceHandler.ProcessRequestAsync(HttpListenerHost appHost, IRequest httpReq, IResponse httpRes, ILogger logger, String operationName, CancellationToken cancellationToken)
	   at Emby.Server.Implementations.HttpServer.HttpListenerHost.RequestHandler(IRequest httpReq, String urlString, String host, String localPath, CancellationToken cancellationToken)
	Source: MediaBrowser.Controller
	TargetSite: Boolean IsAuthorizedToDelete(MediaBrowser.Controller.Entities.User, MediaBrowser.Controller.Entities.Folder[])
	
Posted

Ok, I think I figured out the problem, but not how to solve it.

 

If I use the auth key generated from swagger it works fine.  If I use the auth key I get through Settings->Advanced->Security-API Key it does not work.

 

I am thinking the API key I am generating through the settings page does not have the access to delete, but I don't see any way to change that.

 

How else can I get an API with those permissions that I can store in a config file?

Posted

I think I figured it out.  I need to use /Users/AuthenticateByName for the admin account to get a valid auth key that will allow deleting.

 

Script is now partially work.

Posted

Supply a user ID in your delete request.

Posted

Also supply an empty JSON object {} in the body of the request. I've noticed sometimes that fixes the "Object reference not set to an instance of an object" error, I could totally be wrong though.

Posted

I actually got it fully working and posted the script to GitHub if anyone is interested.

 

https://github.com/clara-j/media_cleaner

 

Works well for me, but only limited testing for it at the moment since I have only tested on my server.

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