Forum Discussion
bpeikes
09-23-2022Cloud Apps
That looks great! How do you use the module to get your api token? Looked at the docs and it wasnt clear?
I know we can get one from the web ui, but I’d rather the people using the script to just need their username and pwd.
bluemetrics
09-23-2022Cloud Apps
Currently, we don't support username and password authentication. This will come up on soon. If you want, you can create your own function or fork the project on GitHub. The function would look something like:
import requests
def login(username: str, password: str) -> str:
data = {'username': username, 'password': passoword}
headers = {
'accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
}
response = requests.post('https://your_app_url/api/v1/authentication/login', headers=headers, data=data)
response.raise_for_status()
content = response.json()
if content['success']:
return content['access_token']
raise ValueError(content['message'])
I hope this helps.
Best regards,
BlueMetrics