I
Immich3y ago
AAAAAA

Some api calls end in 401 despite provided authorization

I am writing an immich prometheus exporter for a neat grafana dashboard. Two api endpoints give me difficulties by throwing a 401 error code even though I am supposed to be logged in. I login through POST /api/auth/login with the admin username and password. then i successfully call server/version and /server-info. when i try to logout or get server stats the following error code is thrown: {"statusCode":401,"message":"Authentication required","error":"Unauthorized"}"} My coding knowledge is limited so bear with me please. So far i have tried it in two ways and both are unsuccessful requests.request("GET", url, headers=headers) and // with auth=HTTPBasicAuth('user','password') requests.request("GET", url, headers=headers, auth=auth) any help is appreciated
6 Replies
MicheI
MicheI3y ago
server-info/version and server-info are public endpoints and don't require authentication. HTTP Basic Auth is unsupported. It's probably best to generate an API key and use that in the x-api-key header.
AAAAAA
AAAAAAOP3y ago
Many thanks! I was able to get through with a Bearer token. may I bother you again. I am desperate at this point. Yesterday I was able to successfully get a 200 response by following your advice. Today, after changing the api key I only manage to get a 401 response. 'Authorization': f'Bearer {token}' gives me a 'Invalid user token'. I have tried it from a remote machine with the same results and i have tried it with porbably 10 different api-keys at this point.
MicheI
MicheI3y ago
You should use the x-api-key header if you're using API keys
AAAAAA
AAAAAAOP3y ago
I did try that as well and it gives me 'invalid api key' as a response message. The only way i have managed to successfully get a 200 response today is by using the accesstoken I generate from /auth/login.
MicheI
MicheI3y ago
1. Create API key
No description
MicheI
MicheI3y ago
2. Use API as follows
No description

Did you find this page helpful?