Can One Workflow Trigger Another?

This topic was automatically generated from Slack. You can find the original thread here.

can one workflow be triggered by another?

Yes, one workflow can be triggered by another using emitted events. The workflow that emits the event is called the emitter, and the workflow that listens for the emitted event is called the listener. You can use the Pipedream REST API to create a subscription that connects the emitter and listener workflows. Here’s a step-by-step guide on how to configure a workflow to listen for emitted events: 1. Pick an existing workflow where you’d like to receive emitted events (the listener) and note its workflow ID. 2. Create a new workflow (the emitter) or pick an existing one and note its workflow ID. 3. Use the Pipedream REST API to create a subscription that delivers the emitted events from the emitter workflow to the listener workflow. Replace p_workflow1 with the emitter’s ID and p_workflow2 with the listener’s ID in the following command: bash curl 'https://api.pipedream.com/v1/subscriptions?emitter_id=p_workflow1&listener_id=p_workflow2&event_name=$errors' \ -X POST \ -H "Authorization: Bearer <api_key>" \ -H "Content-Type: application/json" Now, when the emitter workflow emits an event using $.send.emit(), it will trigger the listener workflow.

Woah , that’s really overcomplicated!

Why not just trigger the other workflow using an HTTP request?

You’re right, using an HTTP request is a simpler alternative to trigger another workflow. Each workflow has a unique endpoint URL that can be used to trigger it via an HTTP request. To trigger a workflow using an HTTP request, follow these steps: 1. In the target workflow (the one you want to trigger), click on the trigger step (e.g., “HTTP / Webhook”). 2. Copy the “Endpoint URL” displayed in the trigger step. 3. In the source workflow (the one that triggers the target workflow), add an “HTTP / Webhook - Send any HTTP Request” action. 4. Paste the copied “Endpoint URL” into the “URL” field of the action step. 5. Set the “Method” to “POST” or any other appropriate HTTP method. 6. Configure any additional request headers or body data as needed. Now, when the source workflow runs, it will send an HTTP request to the target workflow’s endpoint URL, triggering the target workflow.

Right so can this scenario work:

  1. Workflow A has a trigger event being Zoom webinar end
  2. Workflow A sends a HTTP webhook to trigger Workflow B
  3. Workflow B triggers a daily schedule to run send a HTTP webhook to trigger Workflow C (the key data steps)
  4. Workflow D is triggered by a separate Zoom event. It tests the dates and if the event occurs 7+ days past the webinar it sends a HTTP webhook to Workflow C

can the schedule trigger run daily for only a set number of days?

The Schedule trigger itself doesn’t have a built-in option to run daily for a specific number of days. However, you can achieve this by adding a custom code step in your workflow to track the number of runs and stop the workflow after a certain number of runs. Here’s an example of how you can do this: 1. Add a “Daily Schedule” trigger to your workflow. 2. Add a “Code” step after the trigger. 3. Use the following code to track the number of runs and stop the workflow after a specific number of days: const maxRuns = 5; // Set the desired number of days to run the workflow const currentRun = parseInt(this.getMeta().runCount); if (currentRun >= maxRuns) { $.flow.end("Reached the maximum number of runs"); } else { // Your workflow logic here } This code checks the current run count of the workflow and compares it to the maxRuns value. If the current run count is equal to or greater than maxRuns, the workflow will stop. Otherwise, it will continue with your desired logic. Make sure to replace 5 with the number of days you want the workflow to run.

You can also pause/suspend a workflow up to a year.

I’m not sure I understand your intended setup, but you could even have a workflow pause/wait for 24 hours, check a condition, and then call itself back until the condition is fulfilled.

Hmmm but then I’ll end up with endless paused or suspended events

okay no worries. I’ll look at it from another angle

Yeah maybe, I don’t quite understand the objective :laughing: :see_no_evil: