Can I use Python requests library to trigger a flow run through the GraphQL API?

:point_right:t2:Note that: all GraphQL requests are POST requests rather than GET.

The snippet below creates a flow run with the given parameters.

import requests

create_mutation = """
mutation($input: createFlowRunInput!){
    createFlowRun(input: $input){
        flow_run{
            id
        }
    }
}
"""

inputs = dict(
    versionGroupId="339c86be-5c1c-48f0-b8d3-fe57654afe22", parameters=dict(x=6)
)
response = requests.post(
    url="https://api.prefect.io",
    json=dict(query=create_mutation, variables=dict(input=inputs)),
    headers=dict(authorization=f"Bearer {API_KEY}"),
)
print(response.status_code)
print(response.text)

Using version_group_id ensures that even if you register a new version of the flow, the same code will still work since the version_group_id uniquely identifies a specific flow in a project.

For more on version_group_id, see this page.