How to retrieve API tokens with Python
In order to use the API, you must send a valid token with your requests. This article goes over how to get that authentication token.
The token expires in 30 minutes. You can refresh it with the User Refresh Token endpoint. Also, you can use the automation token and specify the required expiration period yourself.
Complete the steps below to be able to run the provided script example.
- Install the following Python library: requests
- Insert your values into the below variables in the script:
-
USERNAME
: your Multilogin X account email -
PASSWORD
: your Multilogin X account password (MD5 encryption is not required)
-
import json
import requests
import hashlib
MLX_BASE = "https://api.multilogin.com"
MLX_LAUNCHER = "https://launcher.mlx.yt:45001/api/v2"
LOCAL_HOST = "http://127.0.0.1"
HEADERS = {'Accept': 'application/json',}
#TODO: Insert your account information in both variables below.
USERNAME = ""
PASSWORD = ""
def sign_in():
payload = {
'email': USERNAME,
'password': hashlib.md5(PASSWORD.encode()).hexdigest()
}
r = requests.post(f'{MLX_BASE}/user/signin', json=payload)
if r.status_code != 200:
print(f'\nFailed to login: {r.text}\n')
else:
response = json.loads(r.text)
token = response.get('data').get('token')
print(token)
return token
# Call the sign_in function to execute it
token = sign_in()