Files
Gainsight/Scripts/API_Tests/api_test.py

89 lines
2.6 KiB
Python
Raw Permalink Normal View History

2023-03-06 09:33:03 -05:00
import json
import requests
import Apikeys
2022-11-03 21:06:46 -04:00
2023-01-30 17:27:36 -05:00
'''
This file is mostly used for random testing of unknown endpoints, like our V1 endpoints.
'''
2023-01-30 17:27:36 -05:00
# url ="https://api.northpass.com/v2/groups/e6ef3e5f-b5a2-4b10-868b-8c165d76d263/learning_paths"
2023-03-06 09:33:03 -05:00
# url = "https://api.northpass.com/v1/media?limit=1"
2023-03-24 15:59:46 -04:00
# url = "https://api.northpass.com/v1/learning_paths"
# url = "https://api2.northpass.com/v2/courses"
2023-03-24 15:59:46 -04:00
# function = sys.argv[1]
apiKey = Apikeys.normsandbox
# normuuid = "3b2ac85d-2bdb-4183-a1c7-e0f49c58c4eb"
group_uuid = "8be78542-ec43-4b5e-a662-77b403b4f049"
2022-11-30 17:19:16 -05:00
2023-01-30 17:27:36 -05:00
# Get Group Memberships:
# url = "https://api.northpass.com/v2/groups/504c4771-223a-447f-9ec6-08e51bc9ca23/memberships"
2023-01-30 17:27:36 -05:00
2023-03-06 09:33:03 -05:00
# Associate a person with a course:
# url = "https://api.northpass.com/v2/people/person_uuid/relationships/courses"
# Associate a person with a Learning Path (Test):
2023-03-24 15:59:46 -04:00
# url = f"https://api.northpass.com/v1/people/{normuuid}/relationships/learning_paths"
2022-11-30 17:19:16 -05:00
# Add Learning Paths to a Group (Test):
url = f"https://api.northpass.com/v1/groups/{group_uuid}/relationships/learning_paths"
2022-11-30 17:19:16 -05:00
2023-03-06 09:33:03 -05:00
def putTest(apiKey, url):
2022-11-03 21:06:46 -04:00
payload = {
"data": {
"type": "media",
"file_name": "/Users/normrasmussen/Downloads/Shopping&Delivery 9 XP.mp4",
}
}
2022-11-03 21:06:46 -04:00
headers = {
"accept": "application/json",
"content-type": "application/json",
"X-Api-Key": apiKey,
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)
2022-11-30 17:19:16 -05:00
def getTest(apiKey, url):
print(url)
print(apiKey)
headers = {"accept": "application/json", "X-Api-Key": apiKey}
2022-11-03 21:06:46 -04:00
response = requests.get(url, headers=headers)
2023-01-30 17:27:36 -05:00
# print(response.text)
2022-12-07 14:10:10 -05:00
jsonResponse = response.json()
2023-03-06 09:33:03 -05:00
jsonResponse = json.dumps(jsonResponse, indent=2)
print(jsonResponse)
# print(jsonResponse["included"][1]["attributes"]["email"])
2022-12-07 14:10:10 -05:00
# print(jsonResponse["data"][1]["attributes"])
2022-11-30 17:19:16 -05:00
2023-01-30 17:27:36 -05:00
2022-11-03 21:06:46 -04:00
def postTest(apiKey, url):
2023-03-06 09:33:03 -05:00
print(url)
# Learning Path ID is for ID and change type to "enrolled-learning-paths"
# payload = {"data": [
# {
# "type": "enrolled-learning-paths",
# "id": "6ef5c9db-81d7-427c-846b-babb9a9a2ad1"
# }
# ]}
# Add Learning Path to a Group Test
payload = {"data": [{"type": "learning-paths", "id": "6ef5c9db-81d7-427c-846b-babb9a9a2ad1"}]}
2022-11-03 21:06:46 -04:00
headers = {
2022-11-30 17:19:16 -05:00
"accept": "application/json",
"content-type": "application/json",
"X-Api-Key": apiKey,
2022-11-03 21:06:46 -04:00
}
2023-03-06 09:33:03 -05:00
response = requests.post(url, json=payload, headers=headers)
2022-11-03 21:06:46 -04:00
print(response.text)
2023-03-06 09:33:03 -05:00
print(response)
2022-11-03 21:06:46 -04:00
2022-11-30 17:19:16 -05:00
2022-11-03 21:06:46 -04:00
if __name__ == "__main__":
# getTest(apiKey, url)
2022-11-30 17:19:16 -05:00
# putTest(apiKey, url)
postTest(apiKey, url)