import requests apiKey = "HWxj6VTNPwbc3WghFTPzr7SjE" # Wild Health groupid = "504c4771-223a-447f-9ec6-08e51bc9ca23" groupurl = f"https://api.northpass.com/v2/groups/{groupid}/memberships" def getemailsfromGroup(apiKey, groupid, groupurl): x = 0 emails = [] while True: x += 1 url = groupurl headers = {"accept": "application/json", "X-Api-Key": apiKey} response = requests.get(url, headers=headers) jsonResponse = response.json() next = jsonResponse["links"] for email in jsonResponse["included"][1]["attributes"]["email"]: emails.append(email) if "next" not in next: break print(emails) if __name__ == "__main__": getemailsfromGroup(apiKey, groupid, groupurl)