Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Authentication Token

The below script snippet shows how to get credentials and an authentication token from Axio360.

get Authentication token

###############################################
# Get credentials and get Authentication Token #
###############################################
import requests 
import base64
import getpass 
import json
import os

#Prompt for Username and Password
print("Please Enter your Axio360 Credentials to logon to \'https://demo-360.axio.com\'")
username = input('Please enter your Axio360 username: ')
password = getpass.getpass(prompt='Please enter your Axio360 password: ')

#Combine the username and password to be encoded
usernamepassword = username + ":" + password
#print("Username and Password to be encoded: ", usernamepassword)

#Base64 Encode provided username and password
string_bytes = usernamepassword.encode("ascii")
base64_bytes = base64.b64encode(string_bytes)
base64_usernamepassword = base64_bytes.decode("ascii")
#print("\nBase64 Encoded Username and Password from prompts: ", base64_usernamepassword)


#Get Authentication Token from Axio
#Axio URL (Demo Instance)
url = "https://demo-graphql-storage.axio.com/authentication"

payload={}
headers = {
  'Authorization': 'Basic ' + base64_usernamepassword,
  'Cookie': 'route=1668429961.865.29.87011|b879090418a14eda8cc513986a82e93c'
}

response = requests.request("GET", url, headers=headers, data=payload)
Axio360Token = response.text

#Display returned raw token
#print("\nAuthentication Token in JSON form:")
#print (Axio360Token)

if response.status_code == 501:
  print("\nAxio360 API Does NOT Currently Support MFA.")
  print("---TERMINATING SCRIPT---")
  exit()

if response.status_code == 200:
  print("\nAxio360 Authentication Token Successfully Generated.")
else:
  print("ERROR GENERATING TOKEN - SCRIPT CANNOT PROCEED")
  print("Response Data:")
  print(response)
  print("response.status_code: ")
  print(response.status_code)
  exit()

#Extract token data from JSON 
json_token_object = json.loads(Axio360Token)
token_data = json_token_object["token"]
Axio360Token = token_data
#print("\nAxio360 Authentication Token Data:")
#print (Axio360Token)
#print("response.status_code: ")
#print(response.status_code)