Skip to main content

Code steps (JavaScript)

The Run code (JavaScript) action runs your own code inside an automation, for example to call an API, reshape data or make a decision that's awkward as branches. It is available on Startup plans and above.

Writing a step​

Your code is the body of async function main(input). Return a JSON-serialisable value.

// input.record.properties, input.data, input.vars, input.secrets
const amount = Number(input.record?.properties?.amount ?? 0);
console.log('amount', amount);

return {
branch: amount > 10000 ? 'large' : 'small',
properties: { deal_size: amount > 10000 ? 'Large' : 'Small' },
};

input contains:

KeyWhat it is
recordThe CRM record the run is about: id, object, name, url, properties
dataThe trigger's data (for example form fields or webhook body)
varsResults saved by earlier steps
secretsThe team secrets you selected for this step
automationid, run_id and team name

Using the result​

  • The return value is saved as {{vars.code}} (rename it with Save the result as), so later steps can use {{vars.code.branch}}, or a branch can test Variable → code.branch.
  • If Update the record with returned "properties" is on, the returned properties are written to the record.
  • console.log output appears in the run's activity log (up to 20 lines).

Calling APIs​

Network access is off unless you list hosts in Allow network access to, for example api.example.com, hooks.slack.com. Then use fetch as usual:

const res = await fetch('https://api.example.com/v1/enrich?email=' + encodeURIComponent(input.record.properties.email), {
headers: { Authorization: `Bearer ${input.secrets.ENRICH_KEY}` },
});
const data = await res.json();
return { properties: { industry: data.industry } };

Only public host names are allowed: IP addresses and hosts that resolve to private networks are refused.

Secrets​

Store API keys under Automations → Secrets. They are encrypted, only passed to steps that select them, and masked in logs.

Limits​

Each run has 5 seconds (up to 10), 64 MB of memory, 50 KB of code and 256 KB of output. Code runs in an isolated sandbox with no file system, environment variables or access to TraffikCo's internal systems. Use Run code now in the editor to try a step against a sample record.