Forked from mcarlton00/Jellyfin-api-auth-example.py
Last active
May 29, 2024 10:45
-
-
Save onstatus/cf915f11103db39cd0159c48cd9eea50 to your computer and use it in GitHub Desktop.
Example for authenticating to Jellyfin API from Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
# Define connection details | |
server_url = 'http://192.168.0.200:8096' | |
username = 'User' | |
password = 'Password' | |
# Build json payload with auth data | |
auth_data = { | |
'username': username, | |
'Pw': password | |
} | |
headers = {} | |
# Build required connection headers | |
authorization = 'MediaBrowser Client="other", Device="my-script", DeviceId="some-unique-id", Version="0.0.0"' | |
headers['Authorization'] = authorization | |
# Authenticate to server | |
r = requests.post(server_url + '/Users/AuthenticateByName', headers=headers, json=auth_data) | |
# Retrieve auth token and user id from returned data | |
token = r.json().get('AccessToken') | |
user_id = r.json().get('User').get('Id') | |
# Update the headers to include the auth token | |
headers['Authorization'] = f'{authorization}, Token="{token}"' | |
# Requests can be made with | |
#requests.get(f'{server_url}/api/endpoint', headers=headers) | |
# User favorites | |
favorites = requests.get(f'{server_url}/Users/{user_id}/Items?Recursive=True&Filters=IsFavorite', headers=headers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment