Files
Gainsight/Scripts/API_Tests/getemails_group.py

36 lines
1.1 KiB
Python
Raw Normal View History

2023-01-30 17:27:36 -05:00
import requests
import pandas as pd
2023-01-30 17:27:36 -05:00
apiKey = "HWxj6VTNPwbc3WghFTPzr7SjE"
# Wild Health
jan_groupid = "504c4771-223a-447f-9ec6-08e51bc9ca23"
july_groupid = "a988c9b0-d9f7-400e-a859-48a0fb167da7"
groupurl = f"https://api.northpass.com/v2/groups/{jan_groupid}/memberships"
2023-01-30 17:27:36 -05:00
def getemailsfromGroup(apiKey, jan_groupid, groupurl):
2023-01-30 17:27:36 -05:00
x = 0
emaillist = []
2023-01-30 17:27:36 -05:00
while True:
x += 1
url = f"https://api.northpass.com/v2/groups/{jan_groupid}/memberships?page={x}"
2023-01-30 17:27:36 -05:00
headers = {"accept": "application/json", "X-Api-Key": apiKey}
response = requests.get(url, headers=headers)
jsonResponse = response.json()
next = jsonResponse["links"]
for emails in jsonResponse["included"]:
email = emails["attributes"]["email"]
print(email)
emaillist.append(email)
2023-01-30 17:27:36 -05:00
if "next" not in next:
break
print(emaillist)
pd.DataFrame(emaillist).to_csv('/Users/normrasmussen/Downloads/emails_in_group.csv')
2023-01-30 17:27:36 -05:00
if __name__ == "__main__":
getemailsfromGroup(apiKey, jan_groupid, groupurl)