105 lines
3.2 KiB
Python
105 lines
3.2 KiB
Python
import requests
|
|
import Apikeys
|
|
import csv
|
|
|
|
BASEURL = "https://api.northpass.com/v2/"
|
|
APIKEY = Apikeys.KARBON
|
|
HEADERS = {
|
|
"accept": "application/json",
|
|
"content-type": "application/json",
|
|
"X-Api-Key": APIKEY,
|
|
}
|
|
ADMIN_LIST = [
|
|
"thea.schlobohm@karbonhq.com",
|
|
"charles+karbon@northpass.com",
|
|
"elizabeth.blass@karbonhq.com",
|
|
"ian.clazie@karbonhq.com",
|
|
"kelly.gabriel@karbonhq.com",
|
|
"richard.newman@karbonhq.com",
|
|
"steven.luu@karbonhq.com",
|
|
]
|
|
|
|
|
|
def get_people_first():
|
|
count = 0
|
|
delete_list = []
|
|
while True:
|
|
count += 1
|
|
person_url = f"{BASEURL}people?page={count}"
|
|
# &filter[partnerships_type][not_eq]=Partnerships::Admin&include=partnerships&page={count}"
|
|
# person_url = f"{BASEURL}people?filter[email][not_cont]=karbonhq.com"
|
|
person_resp = requests.get(person_url, headers=HEADERS)
|
|
persjson = person_resp.json()
|
|
nextlink = persjson["links"]
|
|
|
|
for people in persjson["data"]:
|
|
# print(f"This is just everyone... {people['id']}")
|
|
if people["attributes"]["email"] in ADMIN_LIST:
|
|
pass
|
|
else:
|
|
learneruuid = people["id"]
|
|
print(people["attributes"]["email"])
|
|
delete_list.append(learneruuid)
|
|
|
|
if "next" not in nextlink:
|
|
break
|
|
|
|
del_load = {"payload": delete_list}
|
|
print(f"Deleting {len(delete_list)} people")
|
|
delete_everyone(delete_list)
|
|
|
|
|
|
def get_groups():
|
|
group_list = []
|
|
while True:
|
|
groups_url = f"{BASEURL}groups"
|
|
groups_resp = requests.get(groups_url, headers=HEADERS)
|
|
groupjson = groups_resp.json()
|
|
if len(groupjson['data']) == 0:
|
|
break
|
|
else:
|
|
for groups in groupjson["data"]:
|
|
guids = groups["id"]
|
|
print(f"Deleting Group {groups['attributes']['name']}")
|
|
group_list.append(guids)
|
|
delete_groups(guids)
|
|
|
|
print(f"I've just processed {len(group_list)} groups and deleted them.")
|
|
|
|
|
|
def delete_everyone(uuids):
|
|
if len(uuids) > 1500:
|
|
for chunk in range(0, len(uuids), 1500):
|
|
i = chunk
|
|
payload_1 = []
|
|
i_to_add = uuids[i : i + 1500]
|
|
for person in i_to_add:
|
|
payload_1.append(person)
|
|
print(f"This group of people has a count of {len(payload_1)}")
|
|
payload = {"payload": payload_1}
|
|
del_url = f"{BASEURL}bulk/people/delete"
|
|
response = requests.post(del_url, headers=HEADERS, json=payload)
|
|
print(response.status_code)
|
|
print(response.text)
|
|
|
|
|
|
def delete_groups(guids):
|
|
gdel_url = f"{BASEURL}groups/{guids}"
|
|
gresponse = requests.delete(gdel_url, headers=HEADERS)
|
|
print(f"Deleted group {guids} with status code {gresponse.status_code}")
|
|
codes = [500, 403, 404]
|
|
if gresponse.status_code in codes:
|
|
print(
|
|
f"Hm. Something went wrong. Status code: {response.status_code} and text:"
|
|
)
|
|
print(response.text)
|
|
else:
|
|
pass
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("Getting Group IDs and Deleting groups.")
|
|
get_groups()
|
|
# print("Groups have been deleted. Moving onto people.")
|
|
# get_people_first()
|