Files
Gainsight/Scripts/API_Tests/assignCoursetoGroups.py

97 lines
2.3 KiB
Python
Raw Normal View History

2022-11-08 14:47:53 -05:00
import requests
import Apikeys
2022-11-08 14:47:53 -05:00
apiKey = Apikeys.client
2022-11-08 14:47:53 -05:00
groups = [
"Armonk",
"Babylon",
"Bayside",
"Bedford",
"Cutchogue",
"East Hampton",
"East Setauket",
"Executive",
"Farmingville",
"Franklin Square",
"Garden City",
"Great Neck",
"Greenport",
"Hampton Bays",
"Hamptons",
"Huntington",
"Huntington Station",
"Katonah",
"Locust Valley",
"Long Beach",
"Long Island",
"Long Island City",
"Manhasset",
"Manhattan",
"Massapequa Park",
"Mattituck",
"Merrick",
"Montauk",
"New Hyde Park",
"New York",
"North Fork",
"Ocean Beach",
"Plainview",
"Port Washington",
"Queens",
"Quogue",
"Rockville Centre",
"Roslyn",
"Sag Harbor",
"Sayville",
"Scarsdale",
"Sea Cliff",
"Smithtown",
"Southampton",
"Syosset",
"Westchester",
"Westhampton Beach",
]
2022-11-08 14:47:53 -05:00
def findgroupIDs(apiKey, groups):
groupuuids = []
badGroups = []
for group in groups:
url = "https://api.northpass.com/v2/groups?filter[name][eq]="
headers = {"accept": "application/json", "X-Api-Key": apiKey}
2022-11-08 14:47:53 -05:00
response = requests.get(url + group, headers=headers)
response = response.json()
try:
response = response["data"][0]["id"]
groupuuids.append(response)
except:
badGroups.append(group)
finally:
pass
# print(badGroups)
# print(groupuuids)
assignCourse(apiKey, url, groupuuids)
2022-11-08 14:47:53 -05:00
def assignCourse(apiKey, url, groupuuids):
for group in groupuuids:
try:
2022-11-08 14:47:53 -05:00
url = f"https://api.northpass.com/v2/groups/{group}/relationships/courses"
courseuuid = "10e9b174-cbad-4caa-b0ff-1a7338f2345a"
headers = {
"accept": "application/json",
"content-type": "application/json",
"X-Api-Key": apiKey,
2022-11-08 14:47:53 -05:00
}
payload = {"data": [{"type": "courses", "id": courseuuid}]}
2022-11-08 14:47:53 -05:00
print(f"Group {group} successfully accepted the course")
response = requests.post(url, json=payload, headers=headers)
except:
print(f"Group {group} does not have that course, yet")
finally:
pass
2022-11-08 14:47:53 -05:00
if __name__ == "__main__":
findgroupIDs(apiKey, groups)