Function Webhooks

THIS PAGE
Introduction
Features
Accessing Data
Writing Custom Functions
Testing and Debugging
Best Practices

Introduction

The Function Node in Canonic workflows enables you to write custom JavaScript functions, offering extensive flexibility and control within your workflows. It is equipped with a code editor that allows for intricate logic and data manipulation.

Features

  • Custom Code Execution: Write and execute your own JavaScript functions.
  • Access to Workflow Data: Easily interact with data from other nodes in the workflow.
  • Asynchronous Operations: Support for asynchronous JavaScript, allowing for operations like API calls or database queries.

Accessing Data

In the Function Node's code editor, you can access the workflow's parameters:

module.exports = function (params) {
  // Accessing input data
  const inputData = params.input

  // Accessing data from previous nodes
  const previousData = params["NODE_INDEX"].output // Replace 'NODE_INDEX' with the index of the desired node

  // ... your custom logic ...
}

Writing Custom Functions

  1. Navigate to your Function Node in the workflow.
  2. Open the Code Editor to start writing your JavaScript function.
  3. Implement your logic using the available data and JavaScript capabilities.

Screenshot of the Function Node's code editor

Testing and Debugging

  • Test Thoroughly: After writing your function, use Canonic's built-in testing tools to ensure correct operation.
  • Debugging: Implement console logging and error handling for debugging purposes.

Best Practices

  • Robust Error Handling: Ensure that your code gracefully handles errors and edge cases.
  • Optimized Code: Write efficient code to maintain performance, especially for complex logic or data-heavy operations.
  • Commenting and Documentation: Keep your code well-commented for easier maintenance and understanding.

Note: The Function Node provides a powerful way to introduce custom behavior and logic into your Canonic workflows. Ensure your functions are well-tested, efficient, and maintain the overall integrity of the workflow.

Did you find what you were looking for?
👍
👎
What went wrong?
Need more help?We have a thriving Discordcommunity that can help you with all things Canonic. →