Files
Gainsight/Scripts/API_Tests/get-group-ids.py
2023-07-27 22:20:47 -04:00

39 lines
891 B
Python

import requests
import Apikeys
apiKey = Apikeys.bigideas
groups_dict = {}
def get_groups(apiKey):
count = 0
groups = []
while True:
count += 1
url = f"https://api.northpass.com/v2/groups?page={count}"
headers = {"accept": "application/json", "X-Api-Key": apiKey}
response = requests.get(url, headers=headers)
data = response.json()
nextlink = data["links"]
for response in data["data"]:
group_id = response["id"]
group_name = response["attributes"]["name"]
# print(group_name)
groups_dict = {
"id": group_id,
"name": group_name,
}
groups.append(groups_dict)
if "next" not in nextlink:
break
print(groups)
print(len(groups))
if __name__ == "__main__":
get_groups(apiKey)