Guide: Chain Workflows with Subworkflow

Build a parent workflow that calls two separate subworkflows in sequence, passing data between them. This pattern is useful for keeping complex workflows modular and reusable.

What you will build:

Parent: Webhook → Subworkflow A (validate) → Subworkflow B (notify) → Return
Child A: Manual Trigger → HTTP Request (validate) → Return
Child B: Manual Trigger → Send Email → Return

Time: ~20 minutes

Prerequisites:

  • Tensorify account with a workspace
  • Resend account with a verified domain
  • CLI installed: npm install -g @tensorify.io/cli

Step 1: Build Subworkflow A — "Validate User"

This workflow takes a user ID and returns the user's data.

  1. Dashboard → New Workflow → name it validate-user
  2. Add a Manual trigger with allowWorkflowInvocation enabled
  3. Set mock payload:
{ "userId": "usr_123" }
  1. Add an HTTP Request node connected to Manual's payload:

    • Method: GET
    • URL: https://jsonplaceholder.typicode.com/users/{{ manual.body.userId }}
  2. Add an If node connected to HTTP Request's response:

    • Condition: {{ http_request.status }} == 200
  3. On the true branch: add a Return node connected to HTTP Request's response

  4. On the false branch: add a Return node connected to a Transform node that produces:

    { "error": "User not found", "userId": "{{ manual.body.userId }}" }
    

Copy the Workflow ID from the URL — you will need it in the parent workflow.

Step 2: Build Subworkflow B — "Send Notification"

This workflow sends an email notification with the user data.

  1. Dashboard → New Workflow → name it send-user-notification
  2. Add a Manual trigger with allowWorkflowInvocation enabled
  3. Set mock payload:
{
  "name": "Test User",
  "email": "[email protected]"
}
  1. Add a Code node connected to Manual's payload:
name = input.get("body", {}).get("data", {}).get("name", "User")
return f"New user validated: {name}"
  1. Add a Send Email node connected to Code's result:

  2. Add a Return node connected to a Transform that produces:

    { "notified": true, "userId": "{{ manual.body.data.id }}" }
    

Copy this workflow's Workflow ID too.

Step 3: Build the Parent Workflow

  1. Dashboard → New Workflow → name it user-onboarding-pipeline
  2. Add a Webhook node (or API Endpoint if you want a synchronous response)
  3. Add a Subworkflow node connected to Webhook's payload:
    • Workflow ID: paste the ID of validate-user
  4. Add another Subworkflow node connected to the first Subworkflow's result:
    • Workflow ID: paste the ID of send-user-notification
  5. Connect the second Subworkflow's result to a Return node (if using API Endpoint)

Step 4: Test the Chain

export TENSORIFY_API_KEY="your_key_here"
tensorify watch user-onboarding-pipeline-workflow-id

Set a mock payload on the Webhook node:

{ "userId": "3" }

Click Test → select the Return node → click Run to Selected.

In the terminal, you will see execution logs from all three workflows in sequence. The canvas shows the parent and each subworkflow's outputs at each step.

Step 5: Deploy

All three workflows need to be running for CLI execution mode to work. Either:

  • Run each in a separate terminal: tensorify run <workflowId> for each
  • Or set execution mode to Managed for the subworkflows

In practice, subworkflows inherit the execution context. You only need tensorify run for the parent workflow if all workflows share the same runner configuration.


What You Learned

  • How to compose multiple workflows using the Subworkflow node
  • How to pass data between parent and child workflows via the input handle and Return node
  • How to use If branching inside a subworkflow to handle error states
  • The module composition pattern for keeping complex automations maintainable

Next Steps

On this page