A Flow can be invoked from multiple places. You can invoke it from a button, embed it on your pages, invoke it when DML operations are performed, schedule to run it or even invoke it through REST API call.
In this step-by-step guide, you will learn how to call a Flow from an API, how to pass parameters to the Flow and how Flow will return the values back to the API
Introducing Mastering Salesforce Flows Training Course
Liked this post? We are now offering a complete self-paced, video-based training course on Mastering Salesforce Flows. The course comes with downloadable step-by-step PDF guides, unlimited access, free upgrades, community discussion area, free preview and more. For more details, please click here.
Need Help with Flows?
Need advice on Flows? I also offer advisory & consulting services on Salesforce Flows. So, whether you want to create new Flows or migrate existing automations (Workflow Rules, Process Builder, Triggers) to Flows, I can help you analyze, design, plan & review. To initiate a discussion, please submit the contact form here stating your requirement or schedule a discussion at this URL.
References & Useful URLs
- Help Article – Launch a Flow from the REST API
Hi,
{
“inputs” : [ {
“recordId” : “1234567”,
} ]
}
How can I capture the above body into the flow?
Hi Naveen, please take a look at my blog How to Make HTTP Callout (GET) from Salesforce Flow to Display Contact’s Current Time to see how to process the response body in flows.
Hello thanks for the tutorial,
I’d like to know how to set the statusCode and the response message values in the flow. For example to return a statusCode = 400 and message = ‘Missing required value’ when flow runs and finds out there’s a missing required value.
All I get is below exception in response :
[
{
“actionName”: “XXX_Flow_Api_Name_XXX”,
“errors”: [
{
“statusCode”: “UNKNOWN_EXCEPTION”,
“message”: “An error occurred when executing a flow interview.”,
“fields”: []
}
],
“isSuccess”: false,
“outputValues”: null
}
]
Hi Joshua,
You can’t set the status code and response message. This is handled by Salesforce.
Hi,
This information really helps me to integrate with PBXs.
Allow me to ask a question regarding slide page 27.
How can we know the structure of the request body? Where is the structure below defined?
{
“inputs” : [ { “xxxx ” : “yyyy” } ]
}
Thank you,
Tetsuro
Hi Tetsuro, you can refer to the Salesforce help article https://help.salesforce.com/s/articleView?id=sf.flow_distribute_system_rest.htm&type=5. For each input that you want to pass to the flow, add a key-value pair in the body.
Hi,
Here is the new update from salesforce
https://help.salesforce.com/s/articleView?id=release-notes.rn_automate_flow_release_update_user_context_via_rest_api.htm&type=5&release=242
Does this impact on only on autolaunched as you mentioned that only autolaunched flow can be invoked through rest api
does any other flow can be invoked through rest api?
Hi Nikhil, to the best of my knowledge, currently only auto launched flow can be invoked through REST API.
Hello and thank you for the cool tutorial!
I would like to handover a record of the standard Contact object (defined as an sObject “sO_Contact” variable in the flow) via JSON. How to put it in the right format for the API to accept it?
This won’t work:
[{
“inputs”: {
“sO_Contact”: {
“FirstName”: “Julian”,
“LastName”: “APIviaSObject3”,
“Email”: “julian@customer.de”,
“AccountId”: “0010Q00001ZajJwQAJ”
}
}
}]
“message”: “Can not deserialize: unexpected array at [line:1, column:1]”,
Hi Julian, It should be formatted like this. I have tested this out and it works.
{
"inputs" : [{
"accountRecord" : {
"Name" : "Account from API",
"BillingCountry" : "Singapore"
}
}]
}
Hello Ashish, thank you for this guide.
I’m able to test a custom, auto launched flow from Workbench like on this guide.
However, trying to call the endpoint from a Python script gets me a JSON object describing the Flow: “{“allowsTransactionControl”:false,”category”:null,”configurationEditor”:null,”description”….}
Have you encountered a similar issue, or are Flow APIs only callable from inside Workbench?
Hi Sergio,
The Flow APIs can be called from anywhere. It is not restricted to Workbench. I am not familiar with Python, but can you try if you are able to make other API calls to the same Salesforce org with the same user credentials and and getting a proper response. If you can run it from Workbench, it should work fine from other places also.
Regards,
Ashish