k

    karteekaddanki

    2 years ago
    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?
    Kyle Moon-Wright

    Kyle Moon-Wright

    2 years ago
    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
        }
      }
    }
    ^ you can do this with a prefect client as well.
    k

    karteekaddanki

    2 years ago
    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.