https://prefect.io logo
Title
k

karteekaddanki

07/20/2020, 8:52 PM
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

Kyle Moon-Wright

07/20/2020, 9:17 PM
Hey @karteekaddanki, You can definitely get the id using the GraphQL API and making a query like this:
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

karteekaddanki

07/21/2020, 7:41 AM
Thanks @Kyle Moon-Wright. I'll need to figure out how to make a GraphQL API call from client now. Thanks.
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.