How to retrieve API tokens with Python
For a quick Python API request, copy a regular API token from Multilogin: switch to the workspace you want to automate → click “Info” → click “Copy” next to “API token”. Regular API tokens expire after 30 minutes.
For repeated or longer-running Python automation, generate an automation token instead.
Use the /user/signin Python flow below only when your script needs to authenticate programmatically with an email and password instead of using a token copied from Multilogin.
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.
Which token should I use?
- Regular API token: use for quick API requests. It expires after 30 minutes.
- Automation token: use for repeated or longer-running automation. You choose its expiration period when generating it.
- Refresh token: use only to get a new regular API token. You cannot use it as the bearer token for normal API requests.
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 account email -
PASSWORD: your Multilogin 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()