import requests
import json
import pprint
import csv
import Apikeys

pp = pprint.PrettyPrinter(indent=4)
APIKEY = Apikeys.CHUBB
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 = []
    with open ("/Users/normrasmussen/Downloads/chubb.csv", "r") as csvfile:
        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()
