<@ULVA73B9P> I am trying to filter flow runs based...
# marvin-ai
p
@Marvin I am trying to filter flow runs based on flow_id but following code snippet gives me all flow runs without filtering.
Copy code
url = f"{prefect_api_url}/flow_runs/filter"
    headers = {
        "Content-Type": "application/json"
    }
    payload = {
        "flow_run_filter": {
        "flow_id": {
            "any_": ["xxyy"]
        }
        },
        "sort": "START_TIME_DESC",
        "limit": 20,
        "offset": 0,
        }
    response = <http://requests.post|requests.post>(url, json=payload, headers=headers)
m
It seems your approach to filtering flow runs by
flow_id
is slightly off. In Prefect, the filtering mechanism for flow runs should be structured correctly to match the API's expected input. Here's a refined approach: 1. Ensure that the
flow_id
is correctly placed within the filter structure. 2. Double-check the API endpoint and payload structure. Here's a corrected version of your code snippet:
Copy code
python
import requests

url = f"{prefect_api_url}/flow_runs/filter"
headers = {
    "Content-Type": "application/json"
}
payload = {
    "flow_runs": {  # Ensure the correct key is used
        "flow_id": {
            "any_": ["xxyy"]
        }
    },
    "sort": "START_TIME_DESC",
    "limit": 20,
    "offset": 0,
}
response = <http://requests.post|requests.post>(url, json=payload, headers=headers)
Make sure that the key within the payload matches the expected structure in Prefect's API. If you continue to face issues, you might want to check the Prefect documentation or the GitHub repository for any updates or common issues related to filtering flow runs. For more detailed information, you can refer to the Prefect documentation and the relevant GitHub source code.