Files
Gainsight/Scripts/API_Tests/getuuid_from_email.py

72 lines
1.9 KiB
Python
Raw Normal View History

import pprint
2022-11-08 14:47:53 -05:00
import requests
import Apikeys
2022-11-08 14:47:53 -05:00
pp = pprint.PrettyPrinter(indent=4)
BASEURL = "https://api.northpass.com/v2/people/"
BASEURLNAME = "https://api.northpass.com/v2/people?filter[name][eq]="
BASEURLEMAIL = "https://api.northpass.com/v2/people?filter[email][cont]="
APIKEY = Apikeys.DATASNIPPER
2023-01-05 17:15:12 -05:00
2022-11-08 14:47:53 -05:00
def getfromName(BASEURLNAME, APIKEY):
2022-11-21 16:08:13 -05:00
name = "Someone else"
url = BASEURLNAME + f"{name}"
2022-11-08 14:47:53 -05:00
headers = {
"accept": "*/*",
"x-api-key": APIKEY,
2022-11-08 14:47:53 -05:00
"content-type": "application/json",
}
response = requests.get(url, headers=headers)
2022-11-21 16:08:13 -05:00
if response.status_code == 200:
print("200 Response!")
else:
print("Another error! ")
print(response.status_code)
2022-11-08 14:47:53 -05:00
response = response.json()
2023-01-05 17:15:12 -05:00
# print(response)
# uuid = response["data"][0]["id"]
# print("Learner ID:" )
# print(uuid)
2022-11-08 14:47:53 -05:00
def getfromEmail(BASEURLEMAIL, APIKEY):
2023-01-05 17:15:12 -05:00
# email = "norm2test@northpass.com" # The %2B encodes the + sign in the URL. Using the + sign won't work.
email = "datasnipper.com"
url = BASEURLEMAIL + f"{email}"
2022-11-08 14:47:53 -05:00
headers = {
"accept": "*/*",
"x-api-key": APIKEY,
2022-11-08 14:47:53 -05:00
"content-type": "application/json",
}
response = requests.get(url, headers=headers)
2022-11-21 16:08:13 -05:00
if response.status_code == 200:
print("200 Error!")
else:
print("Another Error!")
response = response.json()
2023-01-05 17:15:12 -05:00
# print(response)
email = response["data"]
2023-01-05 17:15:12 -05:00
# print("Learner ID:" )
#pp.pprint(email)
print(email)
2023-01-05 17:15:12 -05:00
2022-11-21 16:08:13 -05:00
def getfromUuid(BASEURL, APIKEY):
2022-11-21 16:08:13 -05:00
uuid = "57b2b5eb-aa56-4cee-bb32-8c678a2de1b7"
url = BASEURL + uuid
2022-11-21 16:08:13 -05:00
headers = {
"accept": "*/*",
"x-api-key": APIKEY,
2022-11-21 16:08:13 -05:00
"content-type": "application/json",
2023-01-05 17:15:12 -05:00
}
2022-11-21 16:08:13 -05:00
response = requests.get(url, headers=headers)
print(response.status_code)
print(response.text)
2022-11-08 14:47:53 -05:00
2023-01-05 17:15:12 -05:00
2022-11-08 14:47:53 -05:00
if __name__ == "__main__":
# getfromUuid(BASEURL, APIKEY)
getfromEmail(BASEURLEMAIL, APIKEY)
# getfromName(BASEURLNAME, APIKEY)