How to get the latest flow version (flow_id) within a project using GraphQL query?

View in #prefect-community on Slack

ek @ek: Is there a way to use Prefect Client to get a latest flow_id within a project?
here is an example code of what I’m trying to do:

from prefect import Client

api_server="http://prefect-server-apollo:4200"
tenant_id="XXXX"
flow_id="XXXX" 

client = Client(api_server=api_server,tenant_id=tenant_id)
flow_run = client.create_flow_run(
    flow_id=flow_id,
    parameters={"KEY": "VALUE"}
)
print(flow_run)
flow_status = client.get_flow_run_state(flow_run)
print(flow_status)

I want to make flow_id to reflect the latest from the project

Anna_Geller @Anna_Geller: it might be that Kevin answered your question here

ek @ek: in case anyone wants this exact solution, here is the query to get the latest flow_id version from project_id

query {
  flow (
    where: {project_id: {_eq: "PROJECT_ID"}}
    order_by: {version: desc}, limit: 1
  ) {
    id
    name
    version
    created
  }
  
}

Anna_Geller @Anna_Geller: thanks for sharing!