Skip to main content

Code Component

Author and run your own code

Component key: code


The code component allows you to write your own short snippets of JavaScript code, and is handy for writing quick functions or data transformations that are specific to your product or industry. Please see the full article on the code component for information on when a code component is appropriate, and common use cases for a code component.

Code component steps should be succinct and integration-specific. If the code you write could be reused in other integrations, if it needs to handle credentials, or if the code is complex enough that it would benefit from unit tests, etc., you should write a custom component instead.

For some examples of code component usage, check out these quickstart guides:

Authorization Methods#

Code can use the following authorization methods, though no authorization method is required:

Auth TypeKeyDescriptionFields
API Keyapi_keyAPI authorization based on an API key

API Key |  api_key

API Key / Secretapi_key_secretAPI Key / Secret Combination

API Key |  api_key

API Secret |  api_secret

Basic AuthbasicBasic authorization using a username/password combination

Password |  password

Username |  username

OAuth 2.0 - Authorization Codeoauth2OAuth 2.0 authorization using the authorization code grant type

Authorization URL |  auth_uri

Client ID |  client_id

Client Secret |  client_secret

Scopes |  scopes

Access Token URL |  token_uri

OAuth 2.0 - Client Credentialsoauth2_client_credentialsOAuth 2.0 authorization using the client credentials grant type

Client ID |  client_id

Client Secret |  client_secret

Scopes |  scopes

Access Token URL |  token_uri

Private Keyprivate_keyPrivate Key authorization based on a username/private key combination

Private Key |  private_key

Username |  username


Code Block#

Author and run your own code | key: runCode



/ Required
/* Config variables can be accessed by referencing configVars.variableName:   const apiEndpoint = `${configVars.baseUrl}/api`;
 A credential may be optionally specified in the context and its properties may be accessed through the credential variable:   const method = credential.authorizationMethod;
 Log lines can be written out using the logger object:   logger.log("This code component has started");   logger.warn(`Received some unexpected data: ${stepResults.someStep.results}`);
 Results from the trigger and previous steps can be accessed through the stepResults object. The trigger and step names are translated to camelCaseNames. If a previous step named "Get Data From API" returned an object  {"foo": "bar", "baz": 123}, for example:   { foo, baz } = stepResults.getDataFromApi.results
 Return values of a code component follow the form:    return { data: results } results can be a string ("abc"), number (123.4), complex object  ({foo: "bar", baz: 123}), or binary file (like an image or PDF).
 For more information on the code component, see  */
module.exports = async ({ logger, configVars, credential }, stepResults) => {  return { data: null };};
The code to be executed

Output Example Payload#

{  "data": null}