Jump to content

Delete collection with API not working


Recommended Posts

Posted (edited)

I'm getting a successful response but the collection remains. Not sure what is going on here.

import requests
url = "http://example.com:123/Items?6721789&api_key=123abc"
response = requests.delete(url)
if response.status_code == 204:
    print(f"Successfully deleted item {item_id}")
else:
    print(f"Error deleting item {item_id}, response: {response}")

Outputting "Successfully deleted item 6721789" as an example. However the collection was not actually deleted.

Emby log:

Quote

2024-10-12 13:54:53.712 Info Server: http/1.1 DELETE http://emby_remote_ip:42430/Items?=6721789&api_key=x_secret2_x. UserAgent: python-requests/2.31.0
2024-10-12 13:54:53.713 Info Server: http/1.1 Response 204 to host1. Time: 0ms. DELETE http://emby_remote_ip:42430/Items?=6721789&api_key=x_secret2_x
2024

 

Edited by Amything
Posted

I tested removing every item from the collection. That seems to do the trick.

hthgihwaymonk
Posted
delete_url = f'{emby_server_url}/Items/{collection_id}'
headers = {'X-Emby-Token': emby_api_key, 'accept': '*/*'}
response = requests.delete(delete_url, headers=headers)
if response.status_code == 204:
  print(f'Successfully deleted collection with ID "{collection_id}"')
  else:
    print(f'Error deleting collection with ID "{collection_id}": {response.text}')

I use the above and it works.

Posted

@hthgihwaymonk Thanks for the reply!

I've tried that and got "Value cannot be null. (Parameter 'user')". 

I've tried a few things, adding user to the url, as a url param and header value without success. 

hthgihwaymonk
Posted

hmm,  when I use the above snippet - 
 

$ python3.8 embyTools.py delete_all_collections
Successfully deleted collection with ID "3571866"
Successfully deleted collection with ID "3571867"
Successfully deleted collection with ID "3571868"
Successfully deleted collection with ID "3571869"
Successfully deleted collection with ID "3571870"
Successfully deleted collection with ID "3571871"
Successfully deleted collection with ID "3571872"
Successfully deleted collection with ID "3571873"
Successfully deleted collection with ID "3571874"
Successfully deleted collection with ID "3571875"
Successfully deleted collection with ID "3571876"
Successfully deleted collection with ID "3571877"
Successfully deleted collection with ID "3571878"
Successfully deleted collection with ID "3571879"

and after running it, I have no collections:shot_241013_095353.thumb.png.30d57a13978dd80f0b64ad957aab3380.png

Posted

Guess OP forgot headers = {'X-Emby-Token': emby_api_key, 'accept': '*/*'}

hthgihwaymonk
Posted

and for deleting a single collection, if it helps
 

def delete_collection(collection_id):
    delete_url = f'{emby_server_url}/Items/{collection_id}'
    headers = {'X-Emby-Token': emby_api_key, 'accept': '*/*'}
    response = requests.delete(delete_url, headers=headers)
    if response.status_code == 204:
        print(f'Successfully deleted collection with ID "{collection_id}"')
    else:
        print(f'Error deleting collection with ID "{collection_id}": {response.text}')

 

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