Jump to content


Photo

API to delete item from server


  • Please log in to reply
10 replies to this topic

#1 jpc82 OFFLINE  

jpc82

    Member

  • Members
  • 13 posts
  • Local time: 11:36 AM

Posted 13 September 2019 - 07:54 AM

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:8...YYYYYYYYYYYYYY"-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": []
    }, 


#2 ebr OFFLINE  

ebr

    Chief Bottle Washer

  • Administrators
  • 46993 posts
  • Local time: 11:36 AM

Posted 13 September 2019 - 10:53 AM

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.



#3 jpc82 OFFLINE  

jpc82

    Member

  • Members
  • 13 posts
  • Local time: 11:36 AM

Posted 13 September 2019 - 11:04 AM

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



#4 ebr OFFLINE  

ebr

    Chief Bottle Washer

  • Administrators
  • 46993 posts
  • Local time: 11:36 AM

Posted 13 September 2019 - 11:10 AM

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.



#5 jpc82 OFFLINE  

jpc82

    Member

  • Members
  • 13 posts
  • Local time: 11:36 AM

Posted 13 September 2019 - 12:54 PM

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, 13 September 2019 - 12:55 PM.


#6 jpc82 OFFLINE  

jpc82

    Member

  • Members
  • 13 posts
  • Local time: 11:36 AM

Posted 13 September 2019 - 01:00 PM

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[])
	


#7 jpc82 OFFLINE  

jpc82

    Member

  • Members
  • 13 posts
  • Local time: 11:36 AM

Posted 13 September 2019 - 01:27 PM

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?



#8 jpc82 OFFLINE  

jpc82

    Member

  • Members
  • 13 posts
  • Local time: 11:36 AM

Posted 13 September 2019 - 02:45 PM

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.



#9 ebr OFFLINE  

ebr

    Chief Bottle Washer

  • Administrators
  • 46993 posts
  • Local time: 11:36 AM

Posted 13 September 2019 - 03:15 PM

Supply a user ID in your delete request.



#10 roblav96 OFFLINE  

roblav96

    Member

  • Members
  • 25 posts
  • Local time: 11:36 AM

Posted 17 September 2019 - 12:42 AM

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.



#11 jpc82 OFFLINE  

jpc82

    Member

  • Members
  • 13 posts
  • Local time: 11:36 AM

Posted 17 September 2019 - 06:52 PM

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

 

https://github.com/c...j/media_cleaner

 

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






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users