Code

Author and run your own code

Component key: code

Description#

The code component allows you to write and execute short JavaScript snippets of product or industry-specific code within an integration. A full documentation article is available.

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.

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

Actions#

Code Block#

Author and run your own code | key: runCode

InputKeyDefaultNotes

Code

code
/ Required
code
/*
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: ${params.someStep.results}`);
Results from the trigger and previous steps can be accessed through the
params 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 } = params.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
https://prismatic.io/docs/code-component-usage
*/
module.exports = async ({ logger, configVars, credential }, params) => {
return { data: null };
};
The code to be executed

Output Example Payload#

{
"data": null
}