Hello everyone,
I’m trying to automate user invitations using the Vaultwarden API. Despite my efforts to research, I keep encountering authorization errors. I can see from the server logs that the API requests are reaching the server. However, I’m unsure how to authorize correctly since I’m not very experienced with programming or API requests.
Here is my code:
import requests
import json
admin_token = "MyToken"
email_invite = "user@example.com"
payload = {
"email": email_invite
}
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {admin_token}'
}
response = requests.post("https://vaultwarden.mydomain.com/admin/invite",
headers=headers,
json=payload)
print(response.json())
This is the response I receive:
{'error': '', 'errorModel': {'message': 'Authorization failed.', 'object': 'error'}, 'error_description': '', 'exceptionMessage': None, 'exceptionStackTrace': None, 'innerExceptionMessage': None, 'message': 'Authorization failed.', 'object': 'error', 'validationErrors': {'': ['Authorization failed.']}}
I know the request is reaching the server, as indicated by the following log entries:
[request][INFO] POST /admin/invite
[vaultwarden::api::admin][ERROR] Authorization failed.
[response][INFO] (invite_user) POST /admin/invite => 401 Unauthorized
The admin token I’m using is the same one I log in with on the admin webpage for my server. What am I doing wrong?
Kind regards,
Gecko