How to Run JavaScript in Zapier

How to Run JavaScript in Zapier

Using JavaScript in Zapier lets you customize and transform data inside your automations without building a full external service. By adding a Code by Zapier step to your workflow, you can run small JavaScript functions that work with data from previous steps and send clean, structured output to later steps.

This guide explains how to add and configure JavaScript code in a Zap, what the editor supports, and how to format your input and output for reliable results.

Where JavaScript Fits in Zapier Workflows

The Code by Zapier app is a special utility step you can insert between triggers and actions. It is ideal for situations where built-in Zapier actions cannot quite achieve the transformation or logic you need.

Use it for tasks such as:

  • Formatting text, numbers, or dates from earlier steps
  • Combining or splitting values from multiple fields
  • Adding conditional logic before sending data to another app
  • Cleaning up data returned by an API call in Zapier

Each Code by Zapier step runs in a sandboxed environment and is designed for short, synchronous tasks, not long-running jobs or external web servers.

How to Add a Code Step in Zapier

Follow these steps to insert JavaScript code into a Zapier workflow:

  1. Open your Zap and choose + Add step.
  2. Search for Code by Zapier and select it.
  3. Choose the Run JavaScript event.
  4. Click Continue to open the code editor.

Once the step is added, you will see two main sections: Input Data and the Code editor. These define what data goes into your script and what it does with that data.

Using Input Data in Code by Zapier

Input Data in Code by Zapier is how you bring information from earlier steps into your JavaScript. Each entry is converted into a key on the inputData object inside your script.

Set up Input Data in Zapier

To configure inputs in a Zapier JavaScript step:

  1. In the Code by Zapier step, find the Input Data section.
  2. Enter a Key for each field (for example, firstName or order_total).
  3. Map values from previous Zapier steps into the Value area using the field picker.

Inside your script, you can access these values as:

const name = inputData.firstName;
const total = Number(inputData.order_total);

Use lower-case or camelCase keys in Zapier for cleaner JavaScript code, and cast values to numbers, booleans, or arrays when needed.

Supported Data Types in Zapier Code Steps

When passing data into Code by Zapier, typical types include:

  • Strings (text fields from other apps)
  • Numbers (converted with Number() or parseFloat())
  • Booleans (use comparisons like inputData.flag === "true")
  • Arrays and objects (often passed as JSON strings you can parse)

Example for parsing JSON in a Zapier code step:

const items = JSON.parse(inputData.items_json);

Writing JavaScript in Code by Zapier

The JavaScript environment used by Code by Zapier supports modern language features and many standard APIs, but it does not allow every browser or Node.js function.

What You Can Use in Zapier JavaScript

In a JavaScript step in Zapier, you can typically rely on:

  • Core language features like let, const, arrow functions, and template strings
  • Standard objects such as Array, String, Math, and Date
  • Manual HTTP logic only through other Zapier steps, not directly in the code

Custom or external NPM packages cannot be imported directly into Code by Zapier. If you need a dedicated HTTP request or advanced integration, use the Webhooks by Zapier app or another action before or after your code step.

Required Output Format in Zapier Code Steps

At the end of your JavaScript code in Zapier, you must call callback() with either a successful result or an error. This is how Zapier knows the code step is finished and what data to pass forward.

For success, you are expected to return an object:

const fullName = `${inputData.firstName} ${inputData.lastName}`;

callback(null, { fullName });

Key points about Zapier output:

  • The second argument to callback must be an object.
  • Each property on the object becomes a field available to later Zapier steps.
  • You can return arrays or nested objects as values, but the top-level value must be an object.

To signal an error from JavaScript inside Zapier:

if (!inputData.email) {
  callback(new Error("Email is required"));
  return;
}

callback(null, { email: inputData.email });

Throwing an error or calling callback with an Error object will cause the Zapier step to fail and display the message in the Zap run log.

Testing JavaScript Steps in Zapier

After you write your code, use the built-in tester to confirm everything works as expected.

  1. In the Code by Zapier step, click Test or Test step.
  2. Zapier runs the JavaScript using sample data from earlier steps.
  3. Review the output section to see the object you returned via callback.

If the step fails, Zapier displays an error message and stack trace when available, which helps you pinpoint syntax errors, type issues, or missing input fields.

Best Practices for JavaScript in Zapier

To keep your workflows reliable and easy to maintain, follow these tips when using Code by Zapier:

  • Keep scripts short: Use small, focused snippets that do one job well.
  • Avoid long loops: Very long-running scripts may time out in Zapier.
  • Validate input: Check that required fields exist before using them.
  • Return clear field names: Name output keys so later steps in Zapier are easy to configure.
  • Comment tricky logic: Brief comments help you or teammates understand the code later.

Common Use Cases for Code by Zapier

JavaScript in Code by Zapier is most helpful when built-in formatters do not handle your exact requirement. Popular scenarios include:

  • Splitting a single text field into multiple values
  • Merging several inputs into a formatted string
  • Applying custom rounding or percentage calculations
  • Building dynamic objects to send to another API step in Zapier

Whenever possible, use native actions and formatter steps first, then rely on JavaScript only for the pieces that truly require custom logic.

Additional Zapier Resources

To explore the full reference for Code by Zapier, supported features, and environment details, review the official help documentation at this Zapier JavaScript guide. It provides more examples, limits, and environment notes.

If you need broader automation strategy or integration planning beyond a single Zapier workflow, you can also consult resources such as Consultevo for additional guidance on automation design and tooling.

By combining the flexibility of JavaScript with the automation power of Zapier, you can build precise, reusable data transformations that keep your Zaps clean, efficient, and easier to maintain over time.

Need Help With Zapier?

Work with ConsultEvo — a

Zapier Certified Solution Partner

helping teams build reliable, scalable automations that actually move the business forward.


Get Zapier Help

Leave a Comment

Your email address will not be published. Required fields are marked *