How to Initiate a New Workflow from an Existing Workflow?

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

the docs suggest kicking off a new workflow from a workflow—how do I do that for my case?

How do I trigger one workflow from another? I’d like a simple HTTP trigger example and also $.send.emit

To trigger one workflow from another, you can use either an HTTP trigger or the $.send.emit() method. For the HTTP trigger, you’ll need the endpoint URL of the workflow you want to trigger. You can find this URL in the “Trigger” section of the target workflow. Then, in the source workflow, use the axios library to make an HTTP request to the target workflow’s URL. Here’s an example: import { axios } from "@pipedream/platform"; export default { async run() { const targetWorkflowURL = "https://your-target-workflow-url.pipedream.net"; const response = await axios(this, { method: "POST", url: targetWorkflowURL, data: { key: "value", }, }); }, }; For the $.send.emit() method, you’ll need to configure a listener workflow to receive emitted events from the emitter workflow. Follow these steps: 1. Create a new workflow with an HTTP / Webhook trigger (this will be the listener workflow). 2. Get the workflow IDs of both the listener and emitter workflows. You can find the workflow ID in the workflow’s URL in your browser bar — it’s the p_abc123 in https://pipedream.com/@username/p_abc123/. 3. Use the Pipedream REST API to configure the listener to receive events from the emitter. If your listener’s ID is p_abc123 and your emitter’s ID is p_def456, you can run the following command to create this subscription: bash curl -X POST \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"emitter_id": "p_def456", "listener_id": "p_abc123"}' \ https://api.pipedream.com/v1/subscriptions Replace YOUR_API_KEY with your Pipedream API key. 4. In the emitter workflow, use $.send.emit() to send events to the listener workflow: export default { async run() { const eventData = { key: "value", }; await $.send.emit(eventData); }, }; Now, when the emitter workflow runs, it will send events to the listener workflow using $.send.emit().

How do I set up a new HTTP / Webhook trigger (this will be the listener workflow) that will listen for send.emit events emitted by another one of my workflows?

for ‘Event Data’ do I set it to ‘Full HTTP request’?

To set up a new HTTP / Webhook trigger as a listener workflow that listens for $.send.emit() events emitted by another workflow, follow these steps: 1. Create a new workflow with an HTTP / Webhook trigger. This will be your listener workflow. 2. Get the workflow IDs of both the listener and emitter workflows. You can find the workflow ID in the workflow’s URL in your browser bar — it’s the p_abc123 in https://pipedream.com/@username/p_abc123/. 3. Use the Pipedream REST API to configure the listener to receive events from the emitter. This process is called creating a subscription. If your listener’s ID is p_abc123 and your emitter’s ID is p_def456, you can run the following command to create this subscription: bash curl -X POST \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"emitter_id": "p_def456", "listener_id": "p_abc123"}' \ https://api.pipedream.com/v1/subscriptions Replace YOUR_API_KEY with your Pipedream API key. Now, when the emitter workflow runs and uses $.send.emit() to send events, the listener workflow will be triggered by those events.

@pi where do I find my pipedream API key?

where do I find my pipedream API key?

You can find your Pipedream API key in your Account Settings. To access it, follow these steps: 1. Log in to your Pipedream account. 2. Click on “Settings” in the top-right corner. 3. Select “Account” from the dropdown menu. Your API key will be displayed on the Account Settings page. For more details, you can visit the authentication documentation at Authentication.

is it called Workspace ID?

No, the Workspace ID is different from the API key. The Workspace ID is related to your Pipedream workspace, while the API key is used for authentication when making requests to the Pipedream API. To find your Pipedream API key, follow these steps: 1. Log in to your Pipedream account. 2. Click on “Settings” in the top-right corner. 3. Select “Account” from the dropdown menu. Your API key will be displayed on the Account Settings page.

I ran the code above to set up my event emitter/listener. Now how do I test that my subscription is active?

To test if your subscription is active and the event emitter/listener setup is working correctly, you can follow these steps: 1. Run the emitter workflow that contains the $.send.emit() method. You can do this by manually triggering the workflow or by triggering it through its configured trigger (e.g., an HTTP request, a scheduled event, etc.). 2. Check the listener workflow’s execution logs. If the subscription is active and the emitter workflow has successfully sent an event, you should see a new execution in the listener workflow’s logs. The event data sent by the emitter workflow will be available in the listener workflow’s event object. 3. Inspect the event data in the listener workflow’s execution logs to ensure it matches the data sent by the emitter workflow. If you don’t see any new executions in the listener workflow’s logs or the event data is not as expected, double-check your subscription setup and the emitter workflow’s $.send.emit() method to ensure they are configured correctly.

I am using the Google Sheets ‘Find_Row’ step and wondering how to return the id that I do not find when I iterate through all of the values in my sheet?

To return the ID of a row that you do not find when iterating through all the values in your Google Sheet using the ‘Find_Row’ step, you can follow these steps: 1. Use the ‘Find_Row’ step to search for a specific value in your Google Sheet. 2. Check the result of the ‘Find_Row’ step. If the step does not find the desired row, it will return null. 3. If the result is null, you can perform the necessary action, such as adding a new row with the desired ID or handling the case in another way. Here’s an example of how you can use the ‘Find_Row’ step and handle the case when the desired row is not found: const { GoogleSheets } = require("google-sheets-node-api"); const sheets = new GoogleSheets(process.env.GOOGLE_SHEETS_API_KEY); const sheetId = "your_sheet_id"; const sheetName = "your_sheet_name"; const searchValue = "value_to_search"; async function findRow() { const rows = await sheets.getRows(sheetId, sheetName); for (const row of rows) { if (row.your_column_name === searchValue) { return row.id; } } return null; } (async () => { const rowId = await findRow(); if (rowId === null) { console.log("Row not found. Perform necessary action."); // Add a new row with the desired ID or handle the case in another way. } else { console.log(`Row found with ID: ${rowId}`); } })(); Replace your_sheet_id, your_sheet_name, and value_to_search with the appropriate values for your use case. Also, replace your_column_name with the name of the column you want to search in. This example uses the google-sheets-node-api package, which you can install using npm install google-sheets-node-api. Make sure to set the GOOGLE_SHEETS_API_KEY environment variable with your Google Sheets API key.

How do I use Pipedream to check whether a Meetup event has been updated?

To use Pipedream to check whether a Meetup event has been updated, you can create a workflow that periodically fetches the event details from the Meetup API and compares the fetched data with the previous data to detect any changes. Here’s a step-by-step guide: 1. Create a new Pipedream workflow with a “Cron Scheduler” trigger. Set the schedule according to how often you want to check for updates (e.g., every 5 minutes, hourly, etc.). 2. Add a “Run Node.js code” step to fetch the Meetup event details using the Meetup API. You’ll need your Meetup API key and the event ID. Replace YOUR_API_KEY and YOUR_EVENT_ID with the appropriate values: import { axios } from "@pipedream/platform"; const apiKey = "YOUR_API_KEY"; const eventId = "YOUR_EVENT_ID"; const url = `https://api.meetup.com/2/event/${eventId}?key=${apiKey}`; const response = await axios(this, { method: "GET", url: url, }); return response; 3. Add another “Run Node.js code” step to compare the fetched event data with the previous data. You can store the previous data using the Pipedream $checkpoint variable. Here’s an example: ```
const previousEventData = $checkpoint ? $checkpoint.previousEventData : null; const currentEventData = steps.fetch_event_data.$return_value; if (previousEventData && JSON.stringify(previousEventData) !== JSON.stringify(currentEventData)) { console.log(“Meetup event has been updated.”); // Perform any actions you want when the event is updated, e.g., send an email, post to Slack, etc. } else { console.log(“No updates detected.”); } $checkpoint = { previousEventData: currentEventData, };