Skip to main content

Create Basic Workflow

Appsmith Workflows allow you to automate processes, bringing efficiency and connectivity to your applications. 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:

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:




  1. 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.

  2. 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 the executeWorkflow() 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:

  1. 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>"

      }
  2. Click the Run button to send an email. Check your inbox, you must have received an email from demo.smtp.send.email@gmail.com.

  3. Update the Send_Welcome_Email query and remove your email, and add {{this.params.send_email_to}} to it. Adding {{this.params.send_email_to}} replaces the parameter send_email_to with the actual value at run time.

  4. 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 `send_email_to` the query to send email
    const response = await Send_Welcome_Email.run({"send_email_to": data.email});
    // log the response
    console.log(response);

    return true;
    }
    }
  5. Click the Publish button to publish 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:




  1. Click the gear icon ⚙️ in the bottom left corner to configure the workflow settings.
  2. Toggle the Webhook trigger property to configure the workflow as a webhook.
  3. 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.
  4. Click the Publish 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:

  1. Launch the Postman application on your system.
  2. Click on the New button, and choose HTTP request in Postman to create a new request.
  3. Choose the HTTP method as POST.
  4. Enter the workflow URL you copied in the Configure Webhook trigger section.
  5. On the Body tab, select raw, and add the below code in the request body. Here you are setting the parameter value for send_email_to. Remember to replace <add_your_email_address> with your email.
    {
    "email": "<add_your_email_address>"
    }

  6. Click the Send button to execute the request.
  7. 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!

See also