Hello everyone. Is there an API function to get th...
# ask-community
k
Hello everyone. Is there an API function to get the id of the latest version of the flow, given the project_name and the flow_name?
👀 2
k
Hey @karteekaddanki, You can definitely get the id using the GraphQL API and making a query like this:
Copy code
query {
  flow (
      where: {
        name: {_eq: <your_flow_name>}
        project: {
          name: {_eq: <your_project_name>}
        }
    }
  ){
    id,
    name,
    version,
    project {
      name
    }
  }
}
👍 1
^ you can do this with a prefect client as well.
k
Thanks @Kyle Moon-Wright. I'll need to figure out how to make a GraphQL API call from client now. Thanks.
Copy code
def get_latest_flow_id(flow_name, project_name):
    c = Client()
    query = """
        query {
          flow (
              where: {
                name: {_eq: "%s"}
                project: {
                  name: {_eq: "%s"}
                }
            }
          ){
            id,
            name,
            version,
            project {
              name
            }
          }
        }
    """ % (flow_name, project_name)

    result = client.graphql(query)
    return max(result["data"]["flow"], key=lambda x: x["version"])
@Kyle Moon-Wright Thanks for your help. Here is the version that did the trick for me.