Files
Gainsight/Scripts/API_Tests/addalltogroup.py

51 lines
1.3 KiB
Python
Raw Permalink Normal View History

import requests
import Apikeys
apiKey = Apikeys.mizuno_running
def getallUuid(apiKey):
x = 0
uuid = []
while True:
x += 1
url = f"https://api.northpass.com/v2/people?page={x}"
headers = {"accept": "application/json", "X-Api-Key": apiKey}
response = requests.get(url, headers=headers)
jsonResponse = response.json()
next = jsonResponse["links"]
for id in jsonResponse["data"]:
user = id["id"]
uuid.append(user)
if "next" not in next:
break
print(uuid)
addtoGroup(apiKey, uuid)
def addtoGroup(apiKey, uuid):
for x in uuid:
url = f"https://api.northpass.com/v2/people/{x}/relationships/groups"
payload = {
"data": [
{
"type": "membership-groups",
"id": "7383c506-619f-4a83-b1bc-ba766faae06f",
}
]
}
headers = {
"accept": "application/json",
"content-type": "application/json",
"X-Api-Key": apiKey,
}
response = requests.post(url, json=payload, headers=headers)
# jsonResponse = response.json()
print(response)
if __name__ == "__main__":
getallUuid(apiKey)