Create Basic Workflow
Appsmith Workflows allow you to automate processes, bringing efficiency and connectivity to your business. This tutorial guides you through the process of setting up a basic workflow, configuring it as a webhook trigger, integrating and triggering the workflow execution from your Appsmith app.
To learn workflows in Appsmith, you'll build workflow that sends a welcome notification email when new users join your organization. By the end of this tutorial, you will know how to:
- Create a workflow and configure it as a webhook
- Trigger the workflow from an external app (Postman)
Prerequisites
Before you start, make sure you have the following:
- A self-hosted instance of Appsmith with a paid subscription. Refer to the Appsmith installation guides for detailed instructions on setting up your Appsmith instance.
- If you are new to Appsmith, see Tutorial - Basics.
- A REST client. For example, Postman.
Create workflow
Follow these steps to build a notification workflow:
To send notifications to the users you will create a workflow, and configure it as a webhook. Follow these steps to create a webhook workflow within your workspace. All apps in the same workspace can now access the newly created workflow:
-
Click the Create New button in your workspace, and choose Workflow. This action creates a new workflow in your workspace and takes you to the Main JS object code editor. Give a meaningful and unique name to your workflow by editing the name Untitled Workflow 1 to Send_Email_Workflow.
-
In the Main JS object code editor, you will see the
executeWorkflow
function (as shown below). This function executes whenever a workflow run is triggered. It serves as the main function for writing your logic. You'll update theexecuteWorkflow()
function and add code in the Write query to send email section.export default {
/**
* Entry point for Workflow execution. All activities to be executed should be defined here.
* @param data This function takes in a json object as arguments (data) which can be passed when you trigger the workflow.
* @returns boolean Shall return true or false.
*/
async executeWorkflow(data) {
// start writing your code here.
return true;
}
}
You've created your first workflow.
Write query to send email
Follow these steps to write a blank API query for sending email:
-
Add a New blank API query to send a welcome email to the user and configure it as shown below:
- Rename the query to Send_Welcome_Email
- HTTP Method - Select
POST
. - URL - Add
https://hook.us1.make.com/tg6y1fgjds3ysp3x4snt3tfjgu7s747d
in the input box. - Body - In the Body tab, add the below JSON. Remember to replace
add_your_email_address
with your email.{
"email": "add_your_email_address"
}
-
Click the Run button to send an email. Check your inbox, you must have received an email from
demo.smtp.send.email@gmail.com
. -
Update the Send_Welcome_Email query and remove your email, and add
{{this.params.email}}
to it. Adding{{this.params.email}}
replaces the parameteremail
with the actual value at run time. -
Go to the Main JS object and update the
executeworkflow()
function to read the email sent as a parameter.export default {
async executeWorkflow(data) {
//pass email `email` the query to send email
const response = await Send_Welcome_Email.run({"email": data.email});
// log the response
console.log(response);
return true;
}
} -
Click the Deploy button to deploy your latest changes.
You've successfully integrated the email query in workflow.
Configure Webhook trigger
Follow these steps to configure a webhook trigger for the workflow:
- Click the gear icon ⚙️ in the bottom left corner to configure the workflow settings.
- Toggle the Webhook trigger property to configure the workflow as a webhook.
- Copy and save the URL. If you wish to connect your workflow with an external app then you will need the URL. You'll see this in action in the Send email using Postman section.
- Click the Deploy button in the top right corner to publish your workflow.
You've configured the webhook trigger for the workflow. You can now integrate and trigger it from external apps.
Send email using Postman
To simulate the workflow connection from external app, you will use Postman and execute the workflow. Follow these steps to trigger the workflow execution:
- Launch the Postman application on your system.
- Click on the New button, and choose HTTP request in Postman to create a new request.
- Choose the HTTP method as POST.
- Enter the workflow URL you copied in the Configure Webhook trigger section.
- On the Body tab, select raw, and add the below code in the request body. Here you are setting the parameter value for
email
. Remember to replaceadd_your_email_address
with your email.{
"email": "add_your_email_address"
} - Click the Send button to execute the request.
- The below response is generated, and you will receive an email from
demo.smtp.send.email@gmail.com
.{
"success": true,
"message": "Workflow instance started running successfully",
"data": {
"workflowInstanceId": "workflowInstance-rjwbe41QF1P1s90YwYw-1"
}
}
You've successfully executed your first workflow externally, and can integrate the workflow in your external or Appsmith app.
🚩 Congratulations. You have built your first workflow, configured it as a webhook and integrated it with an external app (Postman).
In this tutorial, you explored how to create a workflow, pass parameters to the workflow, configure a webhook trigger for it, and execute workflow from an external app (Postman). You can use these skills to build your own workflow and integrate it with your apps.
Happy Workflow Building!