Still working those luminate templates.... add some scripts for bulk add people. Changed a few todos.
This commit is contained in:
@ -5,7 +5,7 @@ import csv
|
||||
import Apikeys
|
||||
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
APIKEY = Apikeys.ZENJOB
|
||||
APIKEY = Apikeys.CHUBB
|
||||
HEADERS = {
|
||||
"accept": "application/json",
|
||||
"X-Api-Key": APIKEY,
|
||||
@ -21,7 +21,7 @@ def bulk_invite_ppl():
|
||||
}
|
||||
"""
|
||||
payload_1 = []
|
||||
with open ("/Users/normrasmussen/Downloads/Zenjob_empoloyees.csv", "r") as csvfile:
|
||||
with open ("/Users/normrasmussen/Downloads/chubb.csv", "r") as csvfile:
|
||||
for person in csvfile:
|
||||
person = person[:-1]
|
||||
miniload = {
|
||||
|
||||
103
Scripts/API_Tests/bulk_invite_and_props.py
Normal file
103
Scripts/API_Tests/bulk_invite_and_props.py
Normal file
@ -0,0 +1,103 @@
|
||||
import requests
|
||||
import json
|
||||
import pprint
|
||||
import csv
|
||||
import pandas as pd
|
||||
import Apikeys
|
||||
|
||||
pp = pprint.PrettyPrinter(indent=4)
|
||||
APIKEY = Apikeys.CHUBB
|
||||
HEADERS = {
|
||||
"accept": "application/json",
|
||||
"X-Api-Key": APIKEY,
|
||||
}
|
||||
BASEURL = "https://api.northpass.com/v2/"
|
||||
IMPORTFILE = "/Users/normrasmussen/Downloads/chubb.csv"
|
||||
|
||||
|
||||
def bulk_invite_and_group():
|
||||
"""
|
||||
Bulk endpoint which invites new people and adds them to a group via this structure:
|
||||
{
|
||||
"email": "me@mac.com"
|
||||
"groups": "GroupA"
|
||||
}
|
||||
|
||||
This function looks for the group in the CSV as well.
|
||||
"""
|
||||
df = pd.DataFrame()
|
||||
data = pd.read_csv(IMPORTFILE)
|
||||
groups = data["Group"].unique()
|
||||
groups = list(groups)
|
||||
for group in groups:
|
||||
payload = ""
|
||||
tmp_group = data[data.Group == group]
|
||||
people = list(tmp_group["Email"])
|
||||
group = str(tmp_group["Group"].unique())[2:-2]
|
||||
# print(f"Group --> {group} & Email Length --> {len(people)}")
|
||||
url = f"{BASEURL}bulk/people"
|
||||
if len(people) > 1500:
|
||||
for chunk in range(0, len(people), 1500):
|
||||
i = chunk
|
||||
payload_1 = []
|
||||
i_to_add = people[i : i + 1500]
|
||||
for person in i_to_add:
|
||||
miniload = {"email": person, "groups": group}
|
||||
payload_1.append(miniload)
|
||||
print(f"The long length {group} payload has {len(payload_1)}")
|
||||
payload = {"data": {"attributes": {"people": payload_1}}}
|
||||
response = requests.post(url, headers=HEADERS, json=payload)
|
||||
print(f"Completed. Status code is {response.status_code}")
|
||||
else:
|
||||
payload_1 = []
|
||||
for person in people:
|
||||
miniload = {"email": person, "groups": group}
|
||||
payload_1.append(miniload)
|
||||
print(f"The {group} payload has {len(payload_1)}")
|
||||
payload = {"data": {"attributes": {"people": payload_1}}}
|
||||
response = requests.post(url, headers=HEADERS, json=payload)
|
||||
print(f"Completed. Status code is {response.status_code}")
|
||||
print(response.text)
|
||||
|
||||
|
||||
def add_props():
|
||||
errorlist = []
|
||||
df = pd.DataFrame()
|
||||
data = pd.read_csv(IMPORTFILE)
|
||||
for dat in data.iterrows():
|
||||
agency_name = dat[1][3]
|
||||
learner_email = dat[1][2]
|
||||
ppl_search = f"{BASEURL}people?filter[email][eq]={learner_email}"
|
||||
ppl_response = requests.get(ppl_search, headers=HEADERS)
|
||||
try:
|
||||
ppl_data = ppl_response.json()
|
||||
nextlink = ppl_data["links"]
|
||||
learner_uuid = ppl_data["data"][0]["id"]
|
||||
|
||||
# Now update the props
|
||||
prop_url = f"{BASEURL}properties/people/bulk"
|
||||
payload = {
|
||||
"data": [
|
||||
{
|
||||
"attributes": {"properties": {"agency name": agency_name }},
|
||||
"id": learner_uuid,
|
||||
"type": "person_properties",
|
||||
}
|
||||
]
|
||||
}
|
||||
propresponse = requests.post(prop_url, json=payload, headers=HEADERS)
|
||||
print(propresponse.status_code)
|
||||
if propresponse.status_code != 200:
|
||||
error_tupe = (learner_uud, learner_email, agency_name)
|
||||
errorlist.append(error_tupe)
|
||||
else:
|
||||
print(f"Looks like {learner_email} and {agency_name} was successful.")
|
||||
except TypeError as e:
|
||||
pass
|
||||
finally:
|
||||
print(f"Error list: {errorlist}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# bulk_invite_and_group()
|
||||
add_props()
|
||||
Reference in New Issue
Block a user