Hi, I am trying to execute flow run though graphql...
# ask-community
t
Hi, I am trying to execute flow run though graphql query from google cloud functions, how can I set up client so that the cloud functions know what is my client. How can I reach my prefect cloud externally from anywhere?
Copy code
from prefect.client.client import Client
client = Client()
client.graphql(query)
a
You could create a flow run directly using requests and pass the API key into Bearer token:
Copy code
import requests

query = """
 mutation {
  create_flow_run(input: { version_group_id: "fb919cc4-7f74-4ed7-9f3c-71bdd9be69e8" }) {
    id
  }
}
"""

url = "<https://api.prefect.io>"
response = <http://requests.post|requests.post>(
    url, json={"query": query}, headers={"authorization": "Bearer XXX"}
)
print(response.status_code)
print(response.text)
❤️ 1
k
Hi @Tao Bian, if you did
prefect auth login --key API_KEY
, then the Client will pull that API key. You can also pass it into the
Client()
. You can use
client.create_flow_run()
instead of the
client.graphql()
. You can also use
create_flow_run
in our task library which is much more flexible. Just invoke it by calling
.run()
Copy code
create_flow_run.run(flow_name="name", project_name="project")
❤️ 1
t
Thank you, that works!