2024-05-31 15:46:04 -04:00
|
|
|
import requests
|
2025-04-29 15:47:51 -04:00
|
|
|
import pandas as pd
|
2024-05-31 15:46:04 -04:00
|
|
|
import pprint
|
|
|
|
|
import Apikeys
|
|
|
|
|
|
2025-04-29 15:47:51 -04:00
|
|
|
# ************************
|
|
|
|
|
# IF YOU RUN THIS SCRIPT AGAIN WITH HUNDREDS OF THOUSANDS OF ENROLLMENTS
|
|
|
|
|
# SPREAD IT OUT OVER MANY BATCHES, IDEALLY ALL DAY
|
|
|
|
|
# ************************
|
|
|
|
|
|
2024-05-31 15:46:04 -04:00
|
|
|
pp = pprint.PrettyPrinter(indent=4)
|
2025-04-29 15:47:51 -04:00
|
|
|
IMPORTFILE = "~/Downloads/walmart-supplier-mass-grouping.csv"
|
|
|
|
|
APIKEY = Apikeys.SUPPLIERPROD
|
2024-05-31 15:46:04 -04:00
|
|
|
HEADERS = {
|
|
|
|
|
"accept": "application/json",
|
|
|
|
|
"X-Api-Key": APIKEY,
|
|
|
|
|
}
|
2025-04-29 15:47:51 -04:00
|
|
|
BASEURL = "https://api2.northpass.com/v2/"
|
2024-05-31 15:46:04 -04:00
|
|
|
|
2025-04-29 15:47:51 -04:00
|
|
|
def bulk_invite_ppl_under_1500():
|
2024-05-31 15:46:04 -04:00
|
|
|
"""
|
|
|
|
|
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}")
|
|
|
|
|
|
2025-04-29 15:47:51 -04:00
|
|
|
def bulk_invite_ppl_over_1500():
|
|
|
|
|
data = pd.read_csv(IMPORTFILE, encoding = "utf-8")
|
|
|
|
|
emails = list(data["EmailID"].unique())
|
|
|
|
|
url = f"{BASEURL}bulk/people"
|
|
|
|
|
count = 0
|
|
|
|
|
if len(emails) > 499:
|
|
|
|
|
for chunk in range(0, len(emails), 499):
|
|
|
|
|
i = chunk
|
|
|
|
|
payload_1 = []
|
|
|
|
|
i_to_add = emails[i: i + 499]
|
|
|
|
|
for person in i_to_add:
|
|
|
|
|
miniload = {"email": person, "groups": "Active Suppliers" }
|
|
|
|
|
miniload1 = {"email": person, "groups": "All Users" }
|
|
|
|
|
miniload2 = {"email": person, "groups": "Grow With Walmart" }
|
|
|
|
|
payload_1.append(miniload)
|
|
|
|
|
payload_1.append(miniload2)
|
|
|
|
|
payload_1.append(miniload1)
|
|
|
|
|
print(f"The long length payload has {len(payload_1)} people emails")
|
|
|
|
|
payload = {"data": {"attributes": {"people": payload_1}}}
|
|
|
|
|
response = requests.post(url, headers=HEADERS, json=payload)
|
|
|
|
|
count += 1
|
|
|
|
|
print(f"Iteration number {count} out of {int(len(emails))/1500}")
|
|
|
|
|
print(f"Completed. Status code is {response.status_code}")
|
|
|
|
|
else:
|
|
|
|
|
payload_1 = []
|
|
|
|
|
for person in emails:
|
|
|
|
|
miniload = {"email": person, "groups": "Active Suppliers" }
|
|
|
|
|
miniload1 = {"email": person, "groups": "All Users" }
|
|
|
|
|
miniload2 = {"email": person, "groups": "Grow With Walmart" }
|
|
|
|
|
payload_1.append(miniload)
|
|
|
|
|
payload_1.append(miniload2)
|
|
|
|
|
payload_1.append(miniload1)
|
|
|
|
|
print(f"The 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)
|
2024-05-31 15:46:04 -04:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2025-04-29 15:47:51 -04:00
|
|
|
bulk_invite_ppl_over_1500()
|