TS props script, notes
This commit is contained in:
82
Scripts/API_Tests/add_learnerprop.py
Normal file
82
Scripts/API_Tests/add_learnerprop.py
Normal file
@ -0,0 +1,82 @@
|
||||
import requests
|
||||
import pandas as pd
|
||||
|
||||
csv = "/Users/normrasmussen/Downloads/ts_id_roles_test.csv"
|
||||
apiKey = "18Zl2NAzWTE09FHbNEBngNOJO"
|
||||
baseUrlemail = "https://api.northpass.com/v2/people?filter[email][eq]="
|
||||
|
||||
|
||||
def readcsv(csv, apiKey, baseUrlemail):
|
||||
emails = []
|
||||
data = pd.read_csv(csv)
|
||||
emails.extend(data["email"].tolist())
|
||||
getfromEmail(emails, baseUrlemail, apiKey, data)
|
||||
|
||||
|
||||
def getfromEmail(emails, baseUrlemail, apiKey, data):
|
||||
email_ids = {}
|
||||
errors = []
|
||||
for email in emails:
|
||||
url = baseUrlemail + f"{email}"
|
||||
headers = {
|
||||
"accept": "*/*",
|
||||
"x-api-key": apiKey,
|
||||
"content-type": "application/json",
|
||||
}
|
||||
response = requests.get(url, headers=headers)
|
||||
if response.status_code == 200:
|
||||
response = response.json()
|
||||
try:
|
||||
uuid = response["data"][0]["id"]
|
||||
print(uuid)
|
||||
email_ids.update({email: uuid})
|
||||
except Exception as e:
|
||||
errors.append(email)
|
||||
pass
|
||||
else:
|
||||
print("Another Error!")
|
||||
|
||||
# print(email_ids)
|
||||
data["uuid"] = data["email"].map(email_ids)
|
||||
data.dropna(how='any', inplace=True)
|
||||
# print(data)
|
||||
# print(errors)
|
||||
assignProps(data, apiKey)
|
||||
errorstoCsv(errors)
|
||||
|
||||
|
||||
def errorstoCsv(errors):
|
||||
errorcsv = pd.DataFrame(errors)
|
||||
errorcsv.to_csv(
|
||||
path_or_buf="/Users/normrasmussen/Downloads/Talkspace_Emails_Not_Northpass.csv",
|
||||
index=False
|
||||
)
|
||||
|
||||
|
||||
def assignProps(data, apiKey):
|
||||
for row in data.itertuples():
|
||||
print(row)
|
||||
ts_id = row[2]
|
||||
ts_role = row[3]
|
||||
uuid = row[4]
|
||||
url = "https://api.northpass.com/v2/properties/people/bulk"
|
||||
payload = {
|
||||
"data": [{
|
||||
"type": "person_properties",
|
||||
"attributes": {"properties": {
|
||||
"user_id": ts_id,
|
||||
"role_type": ts_role
|
||||
}},
|
||||
"id": uuid,
|
||||
}]}
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"content-type": "application/json",
|
||||
"X-Api-Key": apiKey,
|
||||
}
|
||||
response = requests.post(url, json=payload, headers=headers)
|
||||
print(response)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
readcsv(csv, apiKey, baseUrlemail)
|
||||
36
Scripts/API_Tests/enrollments.py
Normal file
36
Scripts/API_Tests/enrollments.py
Normal file
@ -0,0 +1,36 @@
|
||||
import requests
|
||||
import pandas as pd
|
||||
|
||||
# SPS Commerce
|
||||
apiKey = "VNDXh8K4tLYJ-Nvp78bo6w"
|
||||
|
||||
|
||||
def getEnrollments(apiKey):
|
||||
course_uuid = input("What is the Course UUID? Enter it here: ")
|
||||
x = 0
|
||||
uuid = []
|
||||
while True:
|
||||
x += 1
|
||||
url = f"https://api.northpass.com/v2/courses/{course_uuid}/enrollments"
|
||||
headers = {
|
||||
"accept": "application/json",
|
||||
"X-Api-Key": apiKey
|
||||
}
|
||||
response = requests.get(url, headers=headers)
|
||||
jsonResponse = response.json()
|
||||
next = jsonResponse["links"]
|
||||
|
||||
for id in jsonResponse["data"]:
|
||||
userid= id["attributes"]["person_id"]
|
||||
|
||||
email= id["attributes"]["progress"]
|
||||
uuid.append(user)
|
||||
|
||||
if "next" not in next:
|
||||
break
|
||||
|
||||
# def getCourse():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
getEnrollments(apiKey)
|
||||
@ -3,8 +3,9 @@ import requests
|
||||
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][eq]="
|
||||
apiKey = "JRDpCGQ7vSRiva6t5OkWDr5eJ" #G2
|
||||
#apiKey = "6hUfJdAartHTHhHc0WIRZYPWe" #Walmart
|
||||
apiKey = "JRDpCGQ7vSRiva6t5OkWDr5eJ" # G2
|
||||
# apiKey = "6hUfJdAartHTHhHc0WIRZYPWe" #Walmart
|
||||
|
||||
|
||||
def getfromName(baseUrlname, apiKey):
|
||||
name = "Someone else"
|
||||
@ -20,13 +21,14 @@ def getfromName(baseUrlname, apiKey):
|
||||
else:
|
||||
print("Another error! " + response.status_code)
|
||||
response = response.json()
|
||||
#print(response)
|
||||
#uuid = response["data"][0]["id"]
|
||||
#print("Learner ID:" )
|
||||
#print(uuid)
|
||||
# print(response)
|
||||
# uuid = response["data"][0]["id"]
|
||||
# print("Learner ID:" )
|
||||
# print(uuid)
|
||||
|
||||
|
||||
def getfromEmail(baseUrlemail, apiKey):
|
||||
#email = "norm2test@northpass.com" # The %2B encodes the + sign in the URL. Using the + sign won't work.
|
||||
# email = "norm2test@northpass.com" # The %2B encodes the + sign in the URL. Using the + sign won't work.
|
||||
email = " "
|
||||
url = baseUrlemail + f"{email}"
|
||||
print(url)
|
||||
@ -42,10 +44,11 @@ def getfromEmail(baseUrlemail, apiKey):
|
||||
else:
|
||||
print("Another Error!")
|
||||
response = response.json()
|
||||
#print(response)
|
||||
# print(response)
|
||||
uuid = response["data"]
|
||||
#print("Learner ID:" )
|
||||
#print(uuid)
|
||||
# print("Learner ID:" )
|
||||
# print(uuid)
|
||||
|
||||
|
||||
def getfromUuid(baseUrl, apiKey):
|
||||
uuid = "57b2b5eb-aa56-4cee-bb32-8c678a2de1b7"
|
||||
@ -54,12 +57,13 @@ def getfromUuid(baseUrl, apiKey):
|
||||
"accept": "*/*",
|
||||
"x-api-key": apiKey,
|
||||
"content-type": "application/json",
|
||||
}
|
||||
}
|
||||
response = requests.get(url, headers=headers)
|
||||
print(response.status_code)
|
||||
print(response.text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
getfromUuid(baseUrl, apiKey)
|
||||
#getfromEmail(baseUrlemail, apiKey)
|
||||
#getfromName(baseUrlname, apiKey)
|
||||
# getfromEmail(baseUrlemail, apiKey)
|
||||
# getfromName(baseUrlname, apiKey)
|
||||
|
||||
Reference in New Issue
Block a user