How to create a conditional workflow with HTTP Post requests based on previous step output?

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

How can I have my workflow take the output of a previous step > check for a condition in that output > then proceed to perform a specific HTTP Post request if that condition is met, or, perform a different HTTP Post request if the condition is not met?

For conditionally sending HTTP requests, I recommend taking a look at this guide in our docs:

You can modify that example with an else statement to send a different HTTP request based on the other condition that’s possible in your workflow

Thanks!

How can I have my workflow take the output of a previous step > check for a condition in that output > then proceed to perform a specific HTTP Post request if that condition is met, or, perform a different HTTP Post request if the condition is not met?

To achieve this, you can use a code step in your workflow to check the condition based on the output of a previous step, and then use the HTTP / Webhook app to send the appropriate POST request based on the condition. Here’s a high-level outline of the steps: 1. Add a code step after the step whose output you want to check. 2. In the code step, write a conditional statement to check the condition based on the output of the previous step. 3. If the condition is met, set a variable (e.g., url) to the URL for the specific POST request you want to make. 4. If the condition is not met, set the url variable to the URL for the different POST request. 5. Add the HTTP / Webhook app’s “Send POST Request” action after the code step. 6. Set the URL field in the “Send POST Request” action to the url variable from the code step. Here’s an example of the code step: const previousStepOutput = steps.previous_step_name.$return_value; let url; if (/** your condition based on previousStepOutput **/) { url = "https://example.com/specific-post-request"; } else { url = "https://example.com/different-post-request"; } return { url }; Replace steps.previous_step_name.$return_value with the actual reference to the output of the previous step, and replace the condition in the if statement with your specific condition. After setting up the code step, follow these steps to add the “Send POST Request” action: 1. Search for the HTTP / Webhook app from the step menu. 2. Select the “Send POST Request” action. 3. In the URL field, use the variable from the code step like this: {{steps.code_step_name.url}}. Replace code_step_name with the actual name of your code step. 4. Configure any other required fields for the POST request. 5. At the bottom of the step, click “Test” to run the action and test the configuration. This setup will conditionally send the appropriate POST request based on the output of the previous step.