Creating Custom Actions with Node.js

Leverage the Node Code block to create custom actions in your Integration account. In this section, know how the custom action works, and how to create it with the help of an example.

While Integration provides 1000+ actions for your workflows, you can also create your own custom action using the Node.js action. Integration also provides an action builder that lets you insert custom code and create an action that looks and works exactly the way other actions do.

Getting Started

All your custom actions are saved under the Custom tab in the connectors panel. To create a new custom action using the Node.js block, navigate to the Custom tab, and click on the + icon beside the Node.js action.

The Node.js block will appear on screen where you can see the basic code structure required to create the custom action.

Let’s have a look at the elements that form the code structure for custom action. You can find the complete sample code here.

Code Structure Components

Now that we have seen how to create a new custom action, let’s have a look at the elements that form the code structure for custom action. You can find the complete sample code here. Now that we have seen how to create a new custom action, let’s understand the conventions specified by Integration that you need to follow. These conventions are mainly classified into 3 main blocks of program code as given below:

Supported Modules

You can use specific modules supported by Integration to create custom actions using the Node.js action. Given below is the list of allowlisted modules:

Note: We do not support C++ modules and modules that need to be compiled on binary. This is because, to make these modules work, they should be compiled based on target machine architecture.

Let’s look at an example to understand how to actually go about creating a custom action.

Example

Let’s say, you want to create a custom action for creating a new incident in PagerDuty. We will see how to write code for this action with the help of Integration conventions. You can find the complete action code here.

this.input

In this block you need to define the input fields for the action. All the fields defined here should follow JSON schema structure. Know more about JSON schema here. It contains three main keys (title, type, and properties) for which you need to assign values.

For our sample action, we need to add the following input fields:

Define all these fields inside the properties key as shown below:

You can use Oauth exposed by Integration, to add authorization field for your custom action. Click here to know more about it.

It is important to note that you need set value of minLength to 1 for all the mandatory input fields. This will ensure that the user does not leave any mandatory field blank. In the above example, we have set the value of minLength to 1, for the mandatory Title field. This means that the user will need to enter input in the Title field or otherwise Integration will throw an error.

this.output

In this block, you need to define the output parameters that will be returned by the action. All the fields defined here should follow JSON schema structure. It contains two main keys for which you need to assign values.

Our sample action returns following output parameters:

Define all these output parameters inside the properties key as shown below:

this.execute

In this block, you need to write the entire action logic that will be executed inside the Integration engine. The function defined in this block will have two function parameters: input and output.

You can learn more about request module here.

The this.execute block for our sample workflow is given below:

After you have completed writing the last block, Compile it. The errors, if any, will be highlighted in the console. Once the action is compiled successfully, you will see the action input form in the integration window, as shown below:

Click Save to create the custom action. This will now be added under the Custom tab.

Error Description

Integration throws an error if any of the mandatory keys are not included in your code. Let’s understand it better with the help of example code.

Suppose we have not included title key in the this.input block. Since title is a mandatory key, the custom action will throw an error when you compile the code. The error message is shown below:

The error message is structured as given below:

Similarly, if we do not include type key for Status output field under properties key, in the this.output clock, Integration will throw an error when you compile the code. The error message is shown below:

Log Data

You can capture the log data of the custom actions by using $log() inside the this.execute block. For example, if you want to capture the log details of the input data in the given custom actions, add $log(“formdata ” + JSON.stringify(formdata)); after the formdata section, as shown below:

Here’s the complete code for some of the sample actions to get you started:

Editing and Deleting Custom Action

To edit a custom action, navigate to Custom tab and click the Edit icon given against the custom action name.

Make relevant changes in the Node.js block that appears on screen and Compile it.

Fix errors (if any), and Save the custom action. After this when you add this custom action in any workflow, it will contain the changes made by you.

Note: The existing instances of this custom action will continue to work as per older version, unless you replace them with the modified custom action.

To delete a custom action, navigate to Custom tab and click Delete given against the custom action name.

You will be prompted to confirm the delete request.

Click Delete. This will delete the custom action from your account.

Note: All the existing instances of this custom action which are added to workflows will not be deleted, and continue to function as before. If you want to delete the custom action from your workflows, you will have to explicitly delete them from each workflow.