https://prefect.io logo
Title
n

Nick Coy

09/30/2022, 6:34 PM
Hi, I have been struggling to extract the logs for flow runs from prefect cloud using the api. In prefect 1 I was able to do this with the graph ql query below. How can I do this in prefect 2?
1
query {
    flow_run (where:{
    _and: [
    {start_time: {_gte:"%s"}},
    {start_time: {_lt:"%s"}}
    ]
    }){
    flow {
      id
      name
    }
    scheduled_start_time
    start_time
    name
    id
    version
    task_runs {
      id
      task {
        name
      }
      start_time
      end_time
      logs {
        message
        level
        id
        task_run_id
      }
    }
  }
}
c

Christopher Boyd

09/30/2022, 7:00 PM
HI Nick, Prefect 2 uses the REST API - this should help? https://docs.prefect.io/api-ref/rest-api/#/Logs/read_logs_logs_filter_post
n

Nick Coy

09/30/2022, 7:16 PM
thanks Ill give that a shot
z

Zanie

09/30/2022, 7:48 PM
There’s also the
OrionClient.read_logs
method
If you’re working in Python.