2024-05-31 15:46:04 -04:00
|
|
|
import requests
|
|
|
|
|
import json
|
|
|
|
|
import pprint
|
|
|
|
|
import csv
|
|
|
|
|
import Apikeys
|
|
|
|
|
|
|
|
|
|
pp = pprint.PrettyPrinter(indent=4)
|
2024-06-06 18:28:44 -04:00
|
|
|
APIKEY = Apikeys.CHUBB
|
2024-05-31 15:46:04 -04:00
|
|
|
HEADERS = {
|
|
|
|
|
"accept": "application/json",
|
|
|
|
|
"X-Api-Key": APIKEY,
|
|
|
|
|
}
|
|
|
|
|
BASEURL = "https://api.northpass.com/v2/"
|
|
|
|
|
|
|
|
|
|
def bulk_invite_ppl():
|
|
|
|
|
"""
|
|
|
|
|
Bulk endpoint which invites new people and adds them to a group via this structure:
|
|
|
|
|
{
|
|
|
|
|
"email": "me@mac.com"
|
|
|
|
|
"groups": "GroupA"
|
|
|
|
|
}
|
|
|
|
|
"""
|
|
|
|
|
payload_1 = []
|
2024-06-06 18:28:44 -04:00
|
|
|
with open ("/Users/normrasmussen/Downloads/chubb.csv", "r") as csvfile:
|
2024-05-31 15:46:04 -04:00
|
|
|
for person in csvfile:
|
|
|
|
|
person = person[:-1]
|
|
|
|
|
miniload = {
|
|
|
|
|
"email": person,
|
|
|
|
|
"groups": "Internal Zenjob Testing"
|
|
|
|
|
}
|
|
|
|
|
payload_1.append(miniload)
|
|
|
|
|
payload = payload = { "data": { "attributes": { "people": payload_1 } } }
|
|
|
|
|
print(payload)
|
|
|
|
|
url = f"{BASEURL}bulk/people"
|
|
|
|
|
response = requests.post(url, headers=HEADERS, json=payload)
|
|
|
|
|
print(f"Completed. Status code is {response.status_code}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
bulk_invite_ppl()
|