This message was deleted.
# marvin-in-the-wild
s
This message was deleted.
m
To get a flow's flow runs using the REST API, you can utilize the information provided in the Prefect documentation. Specifically, you can filter for flow runs by their associated flow or deployment. While the REST API documentation does not appear to be explicitly extracted in the results provided, you can use the Python client, which internally uses the GraphQL API, which is the basis for the REST API as well. Here's an example of using the Python client to retrieve flow runs associated with a specific deployment:
Copy code
python
import asyncio
from datetime import datetime, timezone
from prefect import get_client
from prefect.client import FlowRunFilter, DeploymentFilter
from prefect.orion.schemas.sorting import FlowRunSort

async with get_client() as client:
    flow_runs = await client.read_flow_runs(
        flow_run_filter=FlowRunFilter(),
        deployment_filter=DeploymentFilter(
            id='your-deployment-id'
        ),
        sort=FlowRunSort.START_TIME_DESC,
        limit=10  # Adjust the limit as needed
    )
print(flow_runs)
For further details, you'll want to refer to the
DeploymentFilter
and
FlowRunFilter
classes in the filters API reference for more ways to filter flow runs and other objects in your Prefect ecosystem. Make sure to replace
'your-deployment-id'
with the actual deployment ID of the flow you're interested in. You can modify the
FlowRunFilter
to include more specific filtering based on your needs, such as time frame, state, etc. If you still need to use the REST API directly, the Python client examples above can guide you to structure your REST API requests similarly, as the GraphQL queries made by the Python client would be analogous to the REST API calls.
The search did not return the specific documentation on how to retrieve flow runs using the REST API directly, but based on your existing knowledge of using the REST API, you should be able to extrapolate from your example on how to retrieve the flow ID. Generalizing from your example, the REST API endpoint for getting a flow's flow runs might look something like this:
Copy code
python
import requests
import json

account_id = 'your-account-id'
workspace_id = 'your-workspace-id'
deployment_id = 'your-deployment-id'
prefect_token = 'your-prefect-token'

# Endpoint to get flow runs associated with a specific flow or deployment
# This URL will likely change depending on your Prefect version and precise needs
url = f"<https://api.prefect.cloud/api/accounts/{account_id}/workspaces/{workspace_id}/deployments/{deployment_id}/flow_runs>"

# Headers with authorization token
headers = {"Authorization": f"Bearer {prefect_token}"}

# Make a GET request to the API
response = requests.get(url=url, headers=headers)

# Parse the response JSON to get flow runs
flow_runs = json.loads(response.text)

# Example processing of flow_runs
for flow_run in flow_runs:
    print(flow_run['id'], flow_run['name'])
Please replace
your-account-id
,
your-workspace-id
,
your-deployment-id
, and
your-prefect-token
with your actual Prefect account, workspace, and deployment IDs, and your Prefect Cloud access token. Keep in mind that Prefect's REST API documentation may provide more accurate and detailed endpoints with the necessary parameters for filtering and sorting the flow runs. I would recommend checking the latest Prefect documentation or contacting Prefect support for the most up-to-date information on the REST API endpoints.