Skip to main content

Code Component

Author and run your own code

Component key: code

Description#

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:

Code Connections#

API Key#

InputNotes
Input
API Key
string
/ Required
apiKey
Notes
API Key

API Key Secret#

InputNotes
Input
API Key
string
/ Required
apiKey
Notes
API Key
Input
API Secret
password
/ Required
apiSecret
Notes
API Secret

OAuth 2.0 Authorization Code#

InputNotes
Input
Authorize URL
string
/ Required
authorizeUrl
Notes
The OAuth 2.0 Authorization URL for the API
Input
Client ID
string
/ Required
clientId
Notes
Client Identifier of your app for the API
Input
Client Secret
password
/ Required
clientSecret
Notes
Client Secret of your app for the API
Input
Headers
string
Key Value List
headers
Notes
Additional header to supply to authorization requests
Input
Scopes
string
scopes
Notes
Space separated OAuth 2.0 permission scopes for the API
Input
Token URL
string
/ Required
tokenUrl
Notes
The OAuth 2.0 Token URL for the API

Basic Username/Password#

InputNotes
Input
Password
password
/ Required
password
Notes
Password
Input
Username
string
/ Required
username
Notes
Username

OAuth 2.0 Client Credentials#

InputNotes
Input
Client ID
string
/ Required
clientId
Notes
Client Identifier of your app for the API
Input
Client Secret
string
/ Required
clientSecret
Notes
Client Secret of your app for the API
Input
Headers
string
Key Value List
headers
Notes
Additional header to supply to token requests
Input
Scopes
string
scopes
Notes
Space separated OAuth 2.0 permission scopes for the API
Input
Token URL
string
/ Required
tokenUrl
Notes
The OAuth 2.0 Token URL for the API

Private Key#

InputNotes
Input
Private Key
text
/ Required
privateKey
Notes
Private Key
Input
Username
string
/ Required
username
Notes
Username

Triggers#

Code Block Trigger#

Author and run your own code as a trigger | key: runCodeTrigger

InputDefaultNotes
Input
Code
code
/ Required
code
Default
/*  Access config variables by name through the configVars object. e.g.    const apiEndpoint = `${configVars["App Base URL"]}/api`;
  Access the trigger payload using the payload argument. This includes  headers, the body of the request, and more information about the request.
  You can return string, number or complex object data. e.g.    return { payload: { foo: "Hello", bar: 123.45, baz: true } };
  You are also able to return an optional response to the webhook caller.  For example, you can respond with a CSV response like the following:    return {      payload: { foo: "Hello", bar: 123.45, baz: true },      response: { statusCode: 200, contentType: "text/csv", body: "hello,world" },    }
  Full documentation for the code component can be found at:    https://prismatic.io/docs/code-component-usage/
  If your code becomes complex, or requires external dependencies,  please consider building a reusable custom component instead:    https://prismatic.io/docs/custom-components/writing-custom-components/*/
module.exports = async ({ logger, configVars }, payload) => {  const response = {    statusCode: 200,    contentType: "text/plain",    body: "hello",  };  return { payload, response };};
Notes
The code to be executed

Output Example Payload#

{ "payload": None }

Actions#

Code Block#

Author and run your own code | key: runCode

InputDefaultNotes
Input
Code
code
/ Required
code
Default
/*  Access config variables by name through the configVars object. e.g.    const apiEndpoint = `${configVars["App Base URL"]}/api`;
  Access previous steps' results through the stepResults object. Trigger  and step names are camelCased. If the step "Get Data from API" returned  {"foo": "bar", "baz": 123}, you could destructure that data with:    const { foo, baz } = stepResults.getDataFromApi.results;
  You can return string, number or complex object data. e.g.    return { data: { foo: "Hello", bar: 123.45, baz: true } };
  Full documentation for the code component can be found at:    https://prismatic.io/docs/code-component-usage/
  If your code becomes complex, or requires external dependencies,  please consider building a reusable custom component instead:    https://prismatic.io/docs/custom-components/writing-custom-components/*/
module.exports = async ({ logger, configVars }, stepResults) => {  return { data: null };};
Notes
The code to be executed

Output Example Payload#

{  "data": null}