Jump to content

update and add existing library path


Recommended Posts

Posted (edited)

By this python code I add a new library to my Emby server by API

import requests

# Define the Emby server URL and API key
emby_url = 'http://xxxxxxxxxxx:8096'
api_key = 'xxxxxxxxxxxxxxxxxxxxx'

# Define the headers for the API request
headers = {
    'X-Emby-Token': api_key,
    'Content-Type': 'application/json'
}

# Define the payload for creating the new library
payload = {
    "Name": "test1",
    "CollectionType": "movies",  # Change this to the appropriate type if needed
    "Paths": ["/usr/share","/usr/share1"]
}

# Send the request to create the new library
response = requests.post(f'{emby_url}/emby/Library/VirtualFolders', headers=headers, json=payload)

# Check the response status
if response.status_code == 200:
    print("Library created successfully!")
else:
    print(f"Failed to create library. Status code: {response.status_code}")
    print(response.text)

and this works good, but now when I need to add another path(folder) to this library with ID 29590 by another(update) code it sends an error :  Failed to update library. Status code: 404
The file '/Emby/Library/VirtualFolders/29590' cound not be found.

this is the code

import requests

# Define the Emby server URL and API key
emby_url = 'http://xxxxxxxxxxxxxx:8096'
api_key = 'your_api_key_here'

# Define the headers for the API request
headers = {
    'X-Emby-Token': api_key,
    'Content-Type': 'application/json'
}

# Define the library ID (as a string)
library_id = '29590'  # Replace with the actual library ID

# URL to update library details
url = f'{emby_url}/emby/Library/VirtualFolders/{library_id}'

# Prepare the payload with updated values
payload = {
    "Name":'test1',
    
    "Paths": '/usr/share3'
}

# Send the update request
update_response = requests.put(url, headers=headers, json=payload)

if update_response.status_code == 200:
    print("Library updated successfully!")
else:
    print(f"Failed to update library. Status code: {update_response.status_code}")
    print(update_response.text)

i change this code more and more and  couldn't  solve the problem, so anybody can solve it ? 

Edited by maysam
Posted

Hi, this could happen if the server is unable to access the folder that you're trying to add.

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