• Login
  • Register
  • Login Register
    Login
    Username/Email:
    Password:
    Or login with a social network below
  • Forum
  • Website
  • GitHub
  • Status
  • Translation
  • Features
  • Team
  • Rules
  • Help
  • Feeds
User Links
  • Login
  • Register
  • Login Register
    Login
    Username/Email:
    Password:
    Or login with a social network below

    Useful Links Forum Website GitHub Status Translation Features Team Rules Help Feeds
    Jellyfin Forum Support Troubleshooting API update user

    Pages (2): 1 2 Next »

     
    • 0 Vote(s) - 0 Average

    API update user

    Damien
    Offline

    Junior Member

    Posts: 7
    Threads: 2
    Joined: 2023 Nov
    Reputation: 0
    Country:France
    #1
    2023-11-16, 06:58 PM
    Hi everybody,
    I can't find how I can update policies by admin API key and request. Server always respond with an 400 error.
    But I read the doc and I cannot find it out.
    Here simple python code that fails :

    import requests

    ADMIN_API_KEY = 'myadminapikey'
    JELLYFIN_SERVER_URL = 'myjellyfinserverurl'

    JELLYFIN_USER_ID = 'ajellyfinuserid'

    headers = {
        "Authorization": f'MediaBrowser Token="{ADMIN_API_KEY}"',
        "Content-Type": "application/json"
    }

    data = {
        'EnableAllChannels': False,
        'EnableAllFolders': False,
        'EnableContentDownloading': False,
        'EnableLiveTvAccess': False,
        'EnableLiveTvManagement': False,
        'EnableSharedDeviceControl': False,
        'SyncPlayAccess': None,
    }

       
    response = requests.post(f'{JELLYFIN_SERVER_URL}/Users/{JELLYFIN_USER_ID}/Policy', headers=headers, json=data)
    print(response.status_code)


    Thank you for your help !

    Best regards

    Damien    
    qwerty12
    Offline

    Junior Member

    Posts: 30
    Threads: 0
    Joined: 2023 Jun
    Reputation: 3
    #2
    2023-11-18, 02:37 AM
    PHP Code:
    import requests

    ADMIN_API_KEY 
    = 'myadminapikey'
    JELLYFIN_SERVER_URL = 'http://127.0.0.1:8096'
    JELLYFIN_USER_ID = 'a2b6823293f24f0d9620cc7336971e96'

    data = {
        
    'EnableAllChannels': False,
        
    'EnableAllFolders': False,
        
    'EnableContentDownloading': False,
        
    'EnableLiveTvAccess': False,
        
    'EnableLiveTvManagement': False,
        
    'EnableSharedDeviceControl': False,
        
    'SyncPlayAccess': 'None',
    }

    response = requests.get(f'{JELLYFIN_SERVER_URL}/Users/{JELLYFIN_USER_ID}', headers={
        
    'Authorization': f'MediaBrowser Token="{ADMIN_API_KEY}"',
        
    'Accept': 'application/json',
    })
    response.raise_for_status()
    data = {**response.json()['Policy'], **data}
    if 
    'AuthenticationProviderId' not in data:
        
    data['AuthenticationProviderId'] = 'Jellyfin.Server.Implementations.Users.DefaultAuthenticationProvider'
    if 'PasswordResetProviderId' not in data:
        
    data['PasswordResetProviderId'] = 'Jellyfin.Server.Implementations.Users.DefaultPasswordResetProvider'

    response = requests.post(f'{JELLYFIN_SERVER_URL}/Users/{JELLYFIN_USER_ID}/Policy', headers={
        
    'Authorization': f'MediaBrowser Token="{ADMIN_API_KEY}"'
    }, json=data)
    response.raise_for_status() 

    P.S. If the automation is what I suspect it's for, then https://github.com/jellyfin/jellyfin/issues/5415 is a worthwhile read.
    Damien
    Offline

    Junior Member

    Posts: 7
    Threads: 2
    Joined: 2023 Nov
    Reputation: 0
    Country:France
    #3
    2023-11-18, 07:14 AM
    Thank you very much for your answer ! But it does not work.

    Here new code including your solution :

    import requests

    API_KEY = ''
    JELLYFIN_SERVER_URL = ''
    JELLYFIN_USER_ID = ""
    JELLYFIN_ADMIN_ID = ""
    ADMIN_USERNAME = ""
    ADMIN_PW = ""

    def qwerty12_fix() :

    data = {
    'EnableAllChannels': False,
    'EnableAllFolders': False,
    'EnableContentDownloading': False,
    'EnableLiveTvAccess': False,
    'EnableLiveTvManagement': False,
    'EnableSharedDeviceControl': False,
    'SyncPlayAccess': 'None',
    }

    response = requests.get(f'{JELLYFIN_SERVER_URL}/Users/{JELLYFIN_USER_ID}', headers={
    'Authorization': f'MediaBrowser Token="{API_KEY}"',
    'Accept': 'application/json',
    })
    response.raise_for_status()
    data = {**response.json()['Policy'], **data}
    if 'AuthenticationProviderId' not in data:
    data['AuthenticationProviderId'] = 'Jellyfin.Server.Implementations.Users.DefaultAuthenticationProvider'
    if 'PasswordResetProviderId' not in data:
    data['PasswordResetProviderId'] = 'Jellyfin.Server.Implementations.Users.DefaultPasswordResetProvider'

    response = requests.post(f'{JELLYFIN_SERVER_URL}/Users/{JELLYFIN_USER_ID}/Policy', headers={
    'Authorization': f'MediaBrowser Token="{API_KEY}"'
    }, json=data)
    response.raise_for_status()
    headers = {
    "Authorization": f'MediaBrowser Token="{API_KEY}"',
    "Content-Type": "application/json"
    }

    def my_fix() :

    headers = {
    "Authorization": f'MediaBrowser Token="{API_KEY}"',
    "Content-Type": "application/json"
    }

    data = {
    "Username" : ADMIN_USERNAME,
    "Pw" : ADMIN_PW
    }

    response = requests.post(f'{JELLYFIN_SERVER_URL}/Users/AuthenticateByName', headers=headers, json=data)
    TOKEN = response.json().get("AccessToken")

    headers = {
    "Authorization": f'MediaBrowser Token="{TOKEN}"',
    "Content-Type": "application/json"
    }

    data = {
    "Policy" :
    {
    'EnableAllChannels': False,
    'EnableAllFolders': False,
    'EnableContentDownloading': False,
    'EnableLiveTvAccess': False,
    'EnableLiveTvManagement': False,
    'EnableSharedDeviceControl': False,
    'SyncPlayAccess': None
    }
    }

    response = requests.post(f'{JELLYFIN_SERVER_URL}/Users/{JELLYFIN_USER_ID}', headers=headers, json=data)
    print(response.status_code)
    print(response.text)
    print(response.reason)


    so qwerty_12() raises 400 error
    and my_fix() raises also 400 error

    Still lost !
    qwerty12
    Offline

    Junior Member

    Posts: 30
    Threads: 0
    Joined: 2023 Jun
    Reputation: 3
    #4
    2023-11-18, 04:25 PM
    Sorry, I don't have any more ideas. What I posted does work for me locally - I try and copy the web client by getting the existing Policy values too - but the first account I tried with didn't have AuthenticationProviderId and PasswordResetProviderId set, which is needed to call /Policy from what I could tell. It's possible I've missed out more required values. Try running your script again while looking at the Jellyfin server logs - you might spot the exception the server is throwing up.
    Damien
    Offline

    Junior Member

    Posts: 7
    Threads: 2
    Joined: 2023 Nov
    Reputation: 0
    Country:France
    #5
    2023-11-21, 03:48 AM
    Thanks for your response. Jellyfin logs said ; "System.ArgumentNullException: Value cannot be null. (Parameter 'passwordResetProviderId')"
    qwerty12
    Offline

    Junior Member

    Posts: 30
    Threads: 0
    Joined: 2023 Jun
    Reputation: 3
    #6
    2023-11-21, 04:06 PM (This post was last modified: 2023-11-21, 04:07 PM by qwerty12.)
    Right, so data is missing PasswordResetProviderId (and probably AuthenticationProviderId). You can extend
    PHP Code:
    if 'AuthenticationProviderId' not in data:
        
    data['AuthenticationProviderId'] = 'Jellyfin.Server.Implementations.Users.DefaultAuthenticationProvider'
    if 'PasswordResetProviderId' not in data:
        
    data['PasswordResetProviderId'] = 'Jellyfin.Server.Implementations.Users.DefaultPasswordResetProvider' 
    by checking for other "false" values too, like seeing if data['AuthenticationProviderId'] etc. is None, if it's an empty string once stripped and so on.

    ... or just unconditionally set them in data, which might be the easiest thing to do, but probably not the cleanest:

    PHP Code:
    data = {
        
    'EnableAllChannels': False,
        
    'EnableAllFolders': False,
        
    'EnableContentDownloading': False,
        
    'EnableLiveTvAccess': False,
        
    'EnableLiveTvManagement': False,
        
    'EnableSharedDeviceControl': False,
        
    'SyncPlayAccess': 'None',
        
    'AuthenticationProviderId': 'Jellyfin.Server.Implementations.Users.DefaultAuthenticationProvider',
        
    'PasswordResetProviderId': 'Jellyfin.Server.Implementations.Users.DefaultPasswordResetProvider',
    } 
    Damien
    Offline

    Junior Member

    Posts: 7
    Threads: 2
    Joined: 2023 Nov
    Reputation: 0
    Country:France
    #7
    2023-11-21, 05:46 PM
    Thanks but even if I set them unconditionally as you mentionned above, it remains 400 error with log message : "System.ArgumentNullException: Value cannot be null. (Parameter 'passwordResetProviderId')". Weird
    tmsrxzar
    Offline

    Senior Member

    Posts: 755
    Threads: 6
    Joined: 2023 Nov
    Reputation: 20
    #8
    2023-11-21, 05:55 PM
    are you hitting a case sensitivity issue?

    "PasswordResetProviderId" is not "passwordResetProviderId"
    Damien
    Offline

    Junior Member

    Posts: 7
    Threads: 2
    Joined: 2023 Nov
    Reputation: 0
    Country:France
    #9
    2023-11-22, 05:42 AM
    None of these two are working however
    tmsrxzar
    Offline

    Senior Member

    Posts: 755
    Threads: 6
    Joined: 2023 Nov
    Reputation: 20
    #10
    2023-11-22, 06:20 AM (This post was last modified: 2023-11-22, 06:45 AM by tmsrxzar. Edited 1 time in total.)
    started looking into this, not sure where you are reading documentation but i logged it in my browser's dev panel

    the jellyfin web sends different parameters, specifically the headers and the auth to be more specific


    edit

    this code works for me

    Code:
    import requests

    ADMIN_API_KEY = '...'
    JELLYFIN_SERVER_URL = '...'
    JELLYFIN_USER_ID = '...'

    headers = {
        "X-Emby-Authorization": f'MediaBrowser Token="{ADMIN_API_KEY}"',
        "Content-Type": "application/json"
    }

    data = {"EnableContentDownloading":False,
            "AuthenticationProviderId":"Jellyfin.Server.Implementations.Users.DefaultAuthenticationProvider",
            "PasswordResetProviderId":"Jellyfin.Server.Implementations.Users.DefaultPasswordResetProvider"}

    response = requests.post(f'{JELLYFIN_SERVER_URL}/Users/{JELLYFIN_USER_ID}/Policy', headers=headers, json=data)
    print(response.status_code)


    where ADMIN_API_KEY is an api key generated from the dashboard -> api keys
    SERVER_URL is my server
    JELLYFIN_USER_ID is the user id in the address bar when viewing a user (not a username)
    Pages (2): 1 2 Next »

    « Next Oldest | Next Newest »

    Users browsing this thread: 1 Guest(s)


    • View a Printable Version
    • Subscribe to this thread
    Forum Jump:

    Home · Team · Help · Contact
    © Designed by D&D - Powered by MyBB
    L


    Jellyfin

    The Free Software Media System

    Linear Mode
    Threaded Mode