Hi all. I'm trying to create flow runs using the G...
# prefect-community
s
Hi all. I'm trying to create flow runs using the GraphQL API (Prefect 1.0), and am having trouble getting the syntax right to pass a parameter to my flow. Any help you could provide would be greatly appreciated. Details in thread.
This works to create a flow run with no parameters:
Copy code
mutation {
  create_flow_run(
    input: {flow_id: "XXXXXXXXXXX"}
  ) {
    id
  }
}
Since
parameters
is another argument to the create_flow_run function, I figured I could simply add it to the input dict, but every version I have tried has led to an error of
Expected Type JSON
. My first pass was:
Copy code
mutation {
  create_flow_run(
    input: {flow_id: "XXXXXXXXX", parameters: {cycler_id: 123}}
  ) {
    id
  }
}
and I've tried adding quotes in several places, changing the value to a string, but all to no avail. Thanks for any help!
k
If you are doing this, I think you can just use
Client.create_flow_run
?
It will handle that JSON for you if you pass in a dict of parameters
s
I'm running this from a third-party app that gives me limited options to how I can call the API. I can specify a request body, and the only way I was able to get it working was with the mutation syntax.
k
Would this example help?
s
Yeah, that's what I was trying to follow but couldn't figure out how to parse the parameters dict. I guess I could just run the critical parts in Python and figure out what the request ends up looking like. Probably should have just done that.
Thanks, Kevin. I'll post the right answer when I work through that example.
Ok, I was able to get it working. I had to have two different elements in the body. "query" is
Copy code
mutation ($input: createFlowRunInput!) {
  createFlowRun(input: $input) {
    flow_run {
      id
    }
  }
}
and "variables" is
Copy code
{
  "input": {
    "parameters": {
      "cycler_number": 7
    },
    "versionGroupId": "XXXXXXXXXXX"
  }
}
Thanks as always for pointing me in the right direction
k
Nice work!
🤘 1