Title
j

Jinho Chung

11/26/2021, 4:46 PM
I'm new to Prefect, and have been experimenting with running flows on my local machine with a local server as well. So far things have been very intuitive! However I have another nodejs app running locally, and want to try to have that app call the local Prefect server to start a parameterized flow. I can start flows through the UI at localhost:8080 and I've been going through the documentation but things just haven't clicked and I'm not sure how to do this. (Additional disclaimer - I have virtually no experience with GraphQL which probably isn't helping). Thanks for the help and this amazing product!
a

Anna Geller

11/26/2021, 4:54 PM
If you want to trigger a Prefect flow run from a node JS app, you would need to call the “create_flow_run” mutation. I don’t know nodeJS, but here is how you could implement this API request in Python requests:
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 = <http://requests.post|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)
For this, you would need either flow ID, or flow version group ID - I chose the latter here because this ID remains the same even when you later register new versions of the flow: Additionally, you need an API key, which you can create through your Account settings in the UI (URL will be different on local machine):
j

Jinho Chung

11/26/2021, 11:04 PM
@Anna Geller Thank you so much! This was super helpful and cleared up a lot of confusion for me. I was able to get it to run through both the interactive API and via a call form Postman, confirming that it works the way I want it to.
🙌 1