Hi, I'm struggling to create a curl POST kicking o...
# ask-community
p
Hi, I'm struggling to create a curl POST kicking off a create_flow_run on prefect Cloud, with parameters. Is there an example somewhere?
curl 'https://api.prefect.io' -X POST -H 'content-type: application/json' -H 'authorization: Bearer xxx' --data '{
k
Have you seen Anna’s post here ?
p
yes, I can get this to work. The issue is I can't add the
parameters
was there not a util on the top of the API viewer that automatically generated curl statements at one point?
k
I’ve been around since March and I’ve never seen it. Will try one second
p
Copy code
curl '<https://api.prefect.io>'   -X POST   -H 'content-type: application/json' -H 'authorization: Bearer xx'   --data '{
    "query":"mutation {create_flow_run(input: { flow_id: \"12...33\", parameters: \"{ \"input_dir\": \"tt\" }\" }) {id}}"
}'
If I cut and paste the parameters from the graphql api it doesn't escape the outside quotes on the JSON input, but once those two "s are escaped it should be ok.
I don't know what I'm doing wrong, I am not able to pass args via curl.
k
I’m really not getting it myself
a
you will have to adapt the parameters obviously
k
Oh wow this is worth archiving. Will make a closed issue with it later
👍 1
a
I couldn't make it work with multi line strings for some reason
that's why the linebreaks are as "\n"
p
Thank you @Alvaro Durán Tovar - I'm still struggling TBH 😕
a
what's your issue?
to make it work you just have wrap the graphql query into a json like this
Copy code
{"query": ..., "variables": null}
you can have the real example from the developer console like in this screenshot
p
nope, I got it. I was just missing a quote.
Copy code
curl -s <https://api.prefect.io> -H "content-type: application/json" -H "Authorization: Bearer $api_key" --data-binary @- <<-EOF
{"query":"mutation {\n  create_flow_run(input: {\n    flow_id: \"$flow_id\",\n    parameters: \"\"\"{\n    \t\"input_dir\": \"dir_name\"}\"\"\"\n  }) {\n    id\n  }\n}\n","variables":null}
EOF
a
👍
p
Thank you again @Alvaro Durán Tovar 😎