TS props script, notes

This commit is contained in:
Norm Rasmussen
2023-01-05 17:15:12 -05:00
parent 3bf4d6a151
commit 26610f8ae0
12 changed files with 368 additions and 116 deletions

View File

@ -7,15 +7,16 @@ apiKey = ""
groupName = sys.argv[1]
peopleCsv = "/path/to/file/peopletogroups.csv"
def createGroup(groupName, apiKey):
#apiKey = input("What is your API Key? ")
# Create a Group endpoint - params: group_uuid
# apiKey = input("What is your API Key? ")
# 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
"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:
@ -25,36 +26,38 @@ def 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())
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']
groupID = groupresponse["data"]["id"]
ppltoGroup(people, groupID, apiKey)
def ppltoGroup(people, groupID, apiKey):
for uuid in people:
payload = {"data": [
{
"type":"people",
"id":uuid
},
]}
payload = {
"data": [
{"type": "people", "id": uuid},
]
}
# Add People to a Group. Params needed: group_uuid
url = f"https://api.northpass.com/v2/groups/{groupID}/relationships/people"
headers = {
"accept": "*/*",
"content-type": "application/json",
"X-Api-Key": apiKey
}
"X-Api-Key": apiKey,
}
response = requests.post(url, json=payload, headers=headers)
if "404" in response.text:
print("Error returned for this user. Collecting names.")
@ -62,12 +65,10 @@ def ppltoGroup(people, groupID, apiKey):
else:
pass
def errorNames(apiKey, uuid):
url = f"https://api.northpass.com/v2/people/{uuid}"
headers = {
"accept": "application/json",
"X-Api-Key": apiKey
}
headers = {"accept": "application/json", "X-Api-Key": apiKey}
response = requests.get(url, headers=headers)
response = response.json()
errorList = []
@ -75,8 +76,10 @@ def errorNames(apiKey, uuid):
errorList.append(names)
fullNames(errorList)
def fullNames(errorList):
print(errorList)
if __name__ == "__main__":
createGroup(groupName, apiKey)