Login and logout
You must be logged in before starting to work with the API.
After successful authorization, an access token will be returned, which will be required for all other requests.
The default token is valid for 10 minutes and is extended by 10 minutes from the last use.
Attention: the access token is valid only with the client's IP address.
If the token has expired. You need to complete the authorization procedure and get a new token.
Login
Request Structure:
http://<cluster>:<port>/api/login
Post data:
username = <api_login>
password = <api_apss>
The response from the server:
{
"msg": {
"access_token": "ISGYCHKMVPFPLSDRDTJGYDSQVWGHSOMPUERUMFBSMJOGUHRCAUDCCRCBGBVN"
},
"status": "success",
"error": ""
}
Errors:
-Username not found, please log in.
-Wrong password.
Example:
import requests
import json
api_url = "http://<IP>:<PORT>/api/"
api_login = ''
api_apss = ''
access_token = ''
def login():
global access_token
send_token = requests.post(url=api_url+'login/', data={"access_token": access_token})
answer_token = json.loads(send_token.text)
if answer_token['status'] == 'success':
print("Authorized on " + api_url)
if answer_token['status'] == 'error':
print("Not authorized")
print("Login request to "+api_url)
send_login = requests.post(url=api_url+'login/',
data={"username": api_login, "password": api_apss})
answer_login = json.loads(send_login.text)
print(send_login.text)
if answer_login['status'] == 'success':
access_token = answer_login['msg']['access_token']
f = open('access_token.tmp', 'w+')
f.write(access_token)
f.close()
print("Authorization was successful to " + api_url)
else:
print("Failed login to " + api_url)
print("Error: " + answer_login['error'])
Logout
Request Structure:
http://<claster>:<port>/api/logout
Post data:
access_token = <access_token>
The response from the server:
{
"msg": "",
"status": "success",
"error": ""
}
Errors:
-Token not found, please log in.
-The token is not important for this IP address, please log in.
-Token expired please log in.
Example:
import requests
import json
api_url = "http://<IP>:<PORT>/api/"
access_token = 'BLABLALBA'
def logout():
send_logout = requests.post(url=api_url + 'logout', data={"access_token": access_token})
answer_logout = json.loads(send_logout.text)
if answer_logout['status'] == 'success':
print("Logout " + api_url)
else:
print("Error: " + answer_logout['error'])