Heya! I'm trying to use Prefect 2 REST API to crea...
# prefect-cloud
j
Heya! I'm trying to use Prefect 2 REST API to create a flow run. With the help of API docs api/accounts/{account_id}/workspaces/{workspace_id}/flow_runs/ I am able to get the flow run registered on Prefect Cloud, but I can not get it to be put into a work queue for my agent to pick it up 😕
Copy code
curl --request POST \
  --url "<https://api.prefect.cloud/api/accounts/$PREFECT_ACCOUNT_ID/workspaces/$PREFECT_WORKSPACE_ID/flow_runs>" \
  --header "Authorization: Bearer $PREFECT_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "flow_id": "0c6a7af0-e534-44dd-a88a-151db5c289fc",
	"deployment_id": "03e816d7-38f9-4c1f-b036-efc37a1084c1"
}'
The flow just sits there, queue-less in PENDING state. How can I tell it to place the flow run in a queue for one of my agent's to pick it up and run it? Alternatively, since the deployment is associated with a queue, why is Prefect not putting this flow there implicitly? However, the method described by Anna G. in a blog post "How to trigger a flow run from a deployment via API call using Python requests library or from a terminal using curl?" works!
Copy code
❯ curl --request POST \
  --url "<https://api.prefect.cloud/api/accounts/$PREFECT_ACCOUNT_ID/workspaces/$PREFECT_WORKSPACE_ID/deployments/$PREFECT_DEPLOYMENT_ID/create_flow_run>" \
  --header "Authorization: Bearer $PREFECT_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{"name": "your_flow_run", "state": {"type": "SCHEDULED"}}'
Is the API docs wrong, and to create a flow, one must POST to
/create_flow_run
and not
/flow_runs
? 😕 P.S. Originally posted in #prefect-community, but now moved to #prefect-cloud
1
s
Hello! Within your deployment, are you specifying a work queue?
j
Yes.
Copy code
# The work queue that will handle this deployment's runs
work_queue_name: dev_redacted
work_pool_name: null
/create_flow_run
does it correctly and puts the flow run in the queue described by the deployment. In both cases, I'm referencing the same deployment ID
🙌 1
s
Ahhh it might be a docs issue then, I can open up an issue for it - thank you for catching that!