Call one workflow from another
Overview
One workflow can start another by calling its start API from an Action node. Use this when several workflows need the same steps, such as an employee lookup or a notification, so you build those steps once and reuse them.
This page uses two names:
- Calling workflow: the workflow that needs the shared steps.
- Called workflow: the workflow that holds the shared steps.
There is no dedicated "Call workflow" node. The call is made with a standard Action node and the workflow start API described in API call to initiate a workflow.
How it works
An Action node in the calling workflow calls the called workflow's start API, and the called workflow sends its results back in the response to that same call.
Inputs travel in the request body as formData. Outputs come back in the response as data, built from the response template on the called workflow's trigger node.
Step 1: Prepare the called workflow
Set up the workflow that will be called so it accepts an API call and returns the values the calling workflow needs.
- Turn on API initiation. On the trigger node, enable Enable API-triggered initiation of Workflow. The call is rejected if this is off.
- Define the inputs. Add an Initiator Input form with one field for each value the calling workflow will pass in. Note each field's ID, because the call refers to fields by ID.
- Add the shared steps. To return values to the calling workflow, place the steps (for example, the lookup Action node) in the sync block between the workflow trigger and the Initiator Input.
- Run that sync block on API calls. On the trigger node, enable Consider execution of sync block between workflow trigger & initiator input. If this is off, an API call skips the sync block.
- Define the output. On the trigger node, write the Response for API/Web-hook call template and map the values the calling workflow needs.
- Publish the workflow. The call only works on a published, active workflow.
Step 2: Set up the Action node in the calling workflow
-
Create the connection. Use the Leena AI connector (webhook/REST API) with the auth type Leena AI x-app-secret.
-
Set the request. Method
POST, with this URL:https://<regional-base-url>/v2/api/bot/{botId}/app/{appId}/external/initbotIdandappIdare those of the called workflow. The default base URL (AWS India) isworkflows-api.leena.ai. For other regions, see API call to initiate a workflow. -
Build the request body. Map values from the calling workflow into the called workflow's form fields. See the reference below.
-
Place the node. Put the Action node inside a sync block if the calling workflow needs the answer before it moves to the next step.
-
Use the result. Read the returned values from the
dataobject in the Action node's response and map them into later steps.
Example request body, for a called workflow whose form has one field with the ID workerId:
{
"userId": "<initiator's user ID>",
"formData": {
"workerId": "<worker ID from the calling workflow>"
}
}Request and response reference
The request body carries the called workflow's inputs.
| Field | Type | Required | What it holds |
|---|---|---|---|
userId | String | Yes | User ID of the person who becomes the initiator of the called workflow's request |
formData | Object | No | The inputs, as key-value pairs. Each key is a field ID from the called workflow's Initiator Input form |
formDataLabel | Object | No | For dropdown fields: a label and value pair per field ID. Multi-select fields take an array of pairs |
thirdPartyReferenceId | String | No | A reference ID of your own, for tracking |
userObj | Object | No | Overrides the initiator's details: userId, displayName, email, employeeId, name |
The response carries the called workflow's outputs.
| Field | Type | What it holds |
|---|---|---|
success | Boolean | true when the called workflow's request was created |
workflowItemId | String | ID of the request created in the called workflow |
referenceId | String | Reference ID of that run |
data | Object | The values from the trigger node's response template. This is where the calling workflow reads its results |
If the call fails, the response is success: false with an error message.
What happens at run time
- The calling workflow reaches the Action node and sends the call.
- The called workflow checks that API initiation is on, then creates a new request with the given user as initiator.
- The called workflow runs its starting sync block and fills its form from
formData. - The called workflow replies with
success,workflowItemId,referenceIdanddata. - The calling workflow reads
datafrom the Action node's response and continues. - Any remaining steps in the called workflow carry on in the background, as their own request.
Limitations
- Results come back only in the response. Values produced by the called workflow after it has replied are not returned to the calling workflow.
- Each call creates a separate request. The called workflow runs as its own request, with its own status and history. It does not appear as a step inside the calling workflow's request.
- Inputs are not checked in the builder. The calling workflow's builder does not validate
formDataagainst the called workflow's form. If a field ID changes in the called workflow, update the Action node by hand. - The called workflow must stay published. A call to an unpublished workflow, or to one with API initiation turned off, fails.
Updated about 11 hours ago
