Zaki Ali
07/03/2024, 8:47 PMMarvin
07/03/2024, 8:47 PMpython
import requests
url = "<https://api.prefect.io>"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_TOKEN"
}
query = """
{
team {
members {
email
}
}
}
"""
response = <http://requests.post|requests.post>(url + "/graphql", headers=headers, json={'query': query})
print(response.json())
Make sure to replace YOUR_API_TOKEN
with your actual Prefect API token. This query assumes the existence of a team
field, which might require some adjustments based on the exact schema of the Prefect API you are interacting with.
For further, more specific details, I'd recommend consulting the Prefect GraphQL API documentation or reaching out directly to Prefect's support or community forums.
Let me know if you need further assistance.Salman Mohammed
07/03/2024, 8:55 PMMarvin
07/03/2024, 8:55 PMpython
import requests
def get_team_emails(api_token, tenant_ids):
url = "<https://api.prefect.io>"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_token}"
}
all_emails = []
for tenant_id in tenant_ids:
query = f"""
{{
tenant(where: {{id: \"{tenant_id}\"}}) {{
members {{
email
}}
}}
}}
"""
response = <http://requests.post|requests.post>(url + "/graphql", headers=headers, json={'query': query})
try:
emails = response.json()['data']['tenant']['members']
all_emails.extend(member['email'] for member in emails)
except KeyError:
print(f"Could not retrieve emails for tenant ID: {tenant_id}")
return all_emails
# Example usage
api_token = "YOUR_API_TOKEN"
tenant_ids = ["tenant_id_1", "tenant_id_2", "tenant_id_3"]
emails = get_team_emails(api_token, tenant_ids)
print(emails)
1. Replace YOUR_API_TOKEN
with your actual Prefect API token.
2. Replace the tenant_ids
list with the actual tenant IDs you have.
This script sends a GraphQL query for each tenant to fetch the members' emails and aggregates them into a single list.
For more detailed information or schema specifics, refer to Prefect’s GraphQL documentation.
I hope that helps. Feel free to ask if you need further assistance.