Hey Prefect Community, I'm brand new at prefect a...
# ask-community
a
Hey Prefect Community, I'm brand new at prefect and have been trying to figure out how to run a flow with an API call. Is that possible for a locally hosted project? Example:
Copy code
POST - http://{LocalHost}/api/flow_runs 

BODY
{
    "flow_id": "2c1e5ce1-38ef-4a65-a762-ebb14630920d"
}
This correctly creates a flow run, but it remains in pending state and never actually runs.
n
hey @Adam Holderness! welcome you'll want
POST /create_flow_run_from_deployment
otherwise (as you've noticed) you're more or less just creating a flow run record, but not putting it into a (
Scheduled
) state that your worker (client side poller) cares about / notices
fwiw you can use
run_deployment
to do this easily if you find yourself using the SDK, @Marvin short example of this pls
m
To use
run_deployment
in Prefect 3.x, you can follow this simple example. This assumes you are using the Prefect SDK to trigger a deployment programmatically. Here's a basic example of how you might use `run_deployment`:
Copy code
python
from prefect.deployments import run_deployment

# Run a deployment by specifying the deployment name and flow name
deployment_run = run_deployment(
    deployment_name="my-deployment",
    flow_name="my-flow"
)

# You can access the deployment run's ID or other metadata if needed
print(deployment_run.id)
This snippet will trigger a deployment that you've previously created in your Prefect Cloud or Prefect Server setup. You'll need to replace
"my-deployment"
and
"my-flow"
with your actual deployment and flow names. For more details on using deployments in Prefect, you can refer to the Prefect Deploy documentation.
n
doh, almost marvin, its more like
Copy code
deployment_run = run_deployment(
    "flow-name/my-deployment", parameters={...}
)
a
Thank you so much!
n
catjam