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
Notes
API Key

API Key Secret#

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

OAuth 2.0 Authorization Code#

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

Basic Username/Password#

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

OAuth 2.0 Client Credentials#

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

Private Key#

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

Actions#

Code Block#

Author and run your own code | key: runCode

InputDefaultNotes
Input
Code
code
/ Required
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}