Assessments List and Details
Post authorization, using the code snippet below, users can retrieve a list of assessments and details available in their instance.
get assessments
#Import features
import requests
import base64
import getpass
import json
import os
#Clear the output terminal
#print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n")
os.system('CLS')
#Display Welcome Message
print("This is sample Axio360 Automation script:")
###############################################
# Get credentials and get Authentication Token #
###############################################
#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)
#Get List of Assessments
url = "https://demo-graphql-storage.axio.com/graphql"
payload="{\"query\":\"query GetAllAssessments {\\r\\n assessments {\\r\\n id\\r\\n name\\r\\n modelType\\r\\n }\\r\\n}\",\"variables\":{}}"
headers = {
'Authorization': Axio360Token,
'Content-Type': 'application/json',
'Cookie': 'route=1668429961.865.29.87011|b879090418a14eda8cc513986a82e93c'
}
response = requests.request("POST", url, headers=headers, data=payload)
#Format JSON Response to be more readable
Assessments_JSON = response.text
Assessments_List = json.loads(Assessments_JSON)
Assessments_List_Pretty = json.dumps(Assessments_List, indent=2)
#print("\nAssessments List and ID's:")
#print(Assessments_List_Pretty)
print("\nAssessment's Accessible by Supplied User:")
print("=========================================")
#Create index and loop through list showing Collection titles and ID's
index = 0
Assessment_Number=str(index + 1)
for i in Assessments_List["data"]["assessments"]:
print (Assessment_Number + ". " + Assessments_List["data"]["assessments"][index]["name"] + " -- (Assessment id: " + Assessments_List["data"]["assessments"][index]["id"] + ")")
index = index + 1
Assessment_Number=str(index + 1)
#Calculate list length
listlength = len(Assessments_List["data"]["assessments"])
listlength_string = str(listlength)
#Prompt for user to select an assessment
user_assessment_selection = input("\nWhat Assessment would you like to work on: [1-" + listlength_string + "]: ")
user_assessment_selection_int= int(user_assessment_selection)
#Validate response
if user_assessment_selection_int >= 1 and user_assessment_selection_int <= listlength:
user_assessment_selection_int = user_assessment_selection_int - 1
print("\n\n\nYou Picked Assessment: " + Assessments_List["data"]["assessments"][user_assessment_selection_int]["name"])
print("Assessment ID: " + Assessments_List["data"]["assessments"][user_assessment_selection_int]["id"])
else:
print("No valid assessment selected!!!")
exit()
print("\n\n")
#View assessment details?
while True:
display_data = input("Would you like to see the data stored for this assessment? [Y/N]: ")
if display_data.lower() == 'y':
#User typed yes, continue
break
elif display_data.lower() == 'n':
print("Okay, Goodbye!!!")
exit()
else:
print('\n**** You must select either Y or N ****\n')
continue
#Display Assessment Details based on Assessment ID (Assessments_List["data"]["assessments"][user_assessment_selection_int]["id"])
url = "https://demo-graphql-storage.axio.com/graphql"
Assessment_Name = Assessments_List["data"]["assessments"][user_assessment_selection_int]["name"]
Assessment_ID = Assessments_List["data"]["assessments"][user_assessment_selection_int]["id"]
#print("\n\nAbout to use Scenario ID:")
#print(Scenario_ID)
payload="{\"query\":\"query GetAssessmentDetail\\r\\n{\\r\\n assessment(id:\\\"" + Assessment_ID + "\\\") \\r\\n {\\r\\n id\\r\\n name\\r\\n modelType\\r\\n responses \\r\\n {\\r\\n practiceId\\r\\n level\\r\\n targetLevel\\r\\n actionItems \\r\\n {\\r\\n text\\r\\n dueDate\\r\\n }\\r\\n notes\\r\\n {\\r\\n id\\r\\n text\\r\\n dateLastUpdated\\r\\n }\\r\\n }\\r\\n }\\r\\n}\",\"variables\":{}}"
headers = {
'Authorization': Axio360Token,
'Content-Type': 'application/json',
'Cookie': 'route=1668429961.865.29.87011|b879090418a14eda8cc513986a82e93c'
}
response = requests.request("POST", url, headers=headers, data=payload)
#Format JSON Response to be more readable
Assessment_Data = response.text
json_object = json.loads(Assessment_Data)
Assessment_Data_Pretty = json.dumps(json_object, indent=2)
##Display Assessment Data as JSON
print("\nThe following data is stored for Assessment: " + Assessment_Name)
#print(Assessment_Data)
print(Assessment_Data_Pretty)