98 lines
3.0 KiB
Python
98 lines
3.0 KiB
Python
import requests
|
|
import sys
|
|
import http
|
|
import pandas as pd
|
|
|
|
apiKey = "SlpQlju219WnWogn94dQUT6Yt"
|
|
#groupName = sys.argv[1]
|
|
peopleCsv = "/Users/normrasmussen/Downloads/peopletogroups.csv"
|
|
|
|
def createGroup(groupName, apiKey):
|
|
# Create a Group endpoint - params: group_uuid
|
|
url = "https://api.northpass.com/v2/groups"
|
|
payload = {"data": {"attributes": {"name": f"{groupName}"}}}
|
|
headers = {
|
|
"accept": "application/json",
|
|
"content-type": "application/json",
|
|
"X-Api-Key": apiKey
|
|
}
|
|
groupresponse = requests.post(url, json=payload, headers=headers)
|
|
if "already have a group with this name" in groupresponse.text:
|
|
groupName = input("Group already created, what name would you like instead? ")
|
|
print("Got it, thanks! Attempting to create the group now.")
|
|
createGroup(groupName, apiKey)
|
|
else:
|
|
readCSV(apiKey, groupresponse)
|
|
|
|
def readCSV(apiKey, groupresponse):
|
|
people = []
|
|
readExport = pd.read_csv(
|
|
peopleCsv,
|
|
usecols=['UUID'],
|
|
skipinitialspace=True,
|
|
)
|
|
people.extend(readExport['UUID'].tolist())
|
|
getgroupId(people, groupresponse, apiKey)
|
|
|
|
def getgroupId(people, groupresponse, apiKey):
|
|
groupresponse = groupresponse.json()
|
|
groupID = groupresponse['data']['id']
|
|
ppltoGroup(people, groupID, apiKey)
|
|
|
|
def ppltoGroup(people, groupID, apiKey):
|
|
print(groupID)
|
|
|
|
# Add People to a Group. Params needed: group_uuid
|
|
url = f"https://api.northpass.com/v2/groups/{groupID}/relationships/people"
|
|
# Loop through this payload and/or add everyone as new { "type":"people", "id":"uuid"}
|
|
#for uuid in people:
|
|
# itempayload = []
|
|
# jsonpayload = { "type":"people", "id":uuid },
|
|
# itempayload.append(jsonpayload)
|
|
payload = {"data": [
|
|
{
|
|
"type":"people",
|
|
"id":people
|
|
},
|
|
# { "type":"people", "id":people[1]},
|
|
# { "type":"people", "id":people[2]},
|
|
|
|
]}
|
|
headers = {
|
|
"accept": "*/*",
|
|
"content-type": "application/json",
|
|
"X-Api-Key": apiKey
|
|
}
|
|
print(url)
|
|
print(payload)
|
|
print(headers)
|
|
response = requests.post(url, json=payload, headers=headers)
|
|
print(response.text)
|
|
|
|
if __name__ == "__main__":
|
|
ppltoGroup(people="0b31c435-c18b-4573-984e-32cda57045b4", groupID="4f83841f-939f-469f-b98f-29ce7f980c6e",apiKey="SlpQlju219WnWogn94dQUT6Yt")
|
|
#createGroup(groupName, apiKey)
|
|
|
|
|
|
url = "https://api.northpass.com/v2/groups/4c2e807c-2b65-4ce7-a359-2e470fe4f322/relationships/people"
|
|
|
|
payload = {"data": [
|
|
{
|
|
"type": "people",
|
|
"id": "0b31c435-c18b-4573-984e-32cda57045b4"
|
|
},
|
|
{
|
|
"type": "people",
|
|
"id": "0b31c435-c18b-4573-984e-32cda57045b4"
|
|
}
|
|
]}
|
|
headers = {
|
|
"accept": "*/*",
|
|
"content-type": "application/json",
|
|
"X-Api-Key": "SlpQlju219WnWogn94dQUT6Yt"
|
|
}
|
|
|
|
response = requests.post(url, json=payload, headers=headers)
|
|
|
|
print(response.text)
|