Skip to main content
The JavaScript function type allows you to run arbitrary JavaScript or TypeScript code. It is defined like this:
The code should always export a single function as the default export.

Arguments

Arguments are all passed as a single merged object to the function exported from the code: slot-specific fields plus runtime-injected clients. Additionally to function-specific arguments, the following arguments are added to all functions:
  • apiClient / externalApiClient – API client configured with authentication that can be used to make requests to the external API. This parameter is available when code is executed in a context of a specific Connection. Request methods return response data directly; do not read res.data.
  • credentials – authentication credentials for the current connection (only available when externalApiClient is available)
  • internalApiClient - API client configured to make requests to your product’s API (also called Internal API). This client is only available in the context of App Data Schemas at the moment.
  • membrane – API client (MembraneClient instance) for interacting with the Membrane Engine API.

Logging

You can log messages to the console using the console.log function:
To log a JSON object, you need to stringify it:

API Clients

JavaScript method implementations receive API client(s) named apiClient / externalApiClient, internalApiClient, and membrane as arguments. They can be used to make API requests to an external API (based on the current integration or connection), internal API (API of your product), and the Membrane Engine API respectively. The API clients are automatically configured with authentication and base URL settings - you don’t need to provide authentication parameters into each request.

Making Requests

The API client provides methods for making HTTP requests:

Examples

Request Options

Each request method accepts an optional options parameter that can override the default client configuration:

Example with Options

Response

By default, the API client:
  1. Returns the response body for successful requests (status 200–299)
  2. Throws an error for failed requests
  3. Handles authentication and rate limiting errors automatically
You can get the full response including status and headers by setting returnFullResponse: true in the options.

Using in Actions and Flow Nodes

You can use this function in actions or flow nodes with run-javascript type. It is structured a bit differently than the standard definition. Here is an example:

Error Handling

The API client automatically handles common error cases:
  • 401 responses trigger an ACCESS_TOKEN_EXPIRED error that will attempt to refresh credentials
  • 429 responses trigger a RATE_LIMIT_EXCEEDED error that will retry the request with exponential backoff (only in asynchronous mode, e.g., within a flow run)
  • Other error responses (status >= 300) throw a ConnectionError

Using in Connector Files

When used in connector functionality that is stored in connector files (i.e. everything except functions in the connector definition itself), the code is written in a separate file named <function-name>.js. For example: