Arguments
Arguments are all passed as a single object to the function exported from the code. Additionally to function-specific arguments, the following arguments are added to all functions: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.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.engineApiClient– API client (MembraneClient instance) for interacting with the Membrane Engine API.
Logging
You can log messages to the console using theconsole.log function:
API Clients
JavaScript method implementations receive API client(s) namedexternalApiClient, internalApiClient, and engineApiClient 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 optionaloptions parameter that can override the default client configuration:
Example with Options
Response
By default, the API client:- Returns the response body for successful requests (status 200–299)
- Throws an error for failed requests
- Handles authentication and rate limiting errors automatically
returnFullResponse: true in the options.
Using in Actions and Flow Nodes
You can use this function in actions or flow nodes withrun-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: