Code steps are a way to extend Zapier to run small snippets of Python or JavaScript as part of your Zaps. This tutorial is for JavaScript Code steps, but you can read about Python Code steps here.
Code steps can be used as both triggers and actions.
JavaScript is an advanced programming language. If you're not familiar with using JavaScript, it's recommended to ask a developer for help. Zapier does not offer email support for code steps. If you run into trouble, we recommend asking questions on StackOverflow and tagging them with "Zapier".
For tips and inspiration, check out JavaScript code examples.
The environment is vanilla Node.js v8.10.0 which runs JavaScript. Your script is sandboxed and can only run for a limited amount of time and within a limited amount of memory—the exact limits are based on plan level. If you exceed those limits, your script will be stopped.
In your Code step, you have access to the inputData
variable, where all values will be strings. Since the amount of data that might feed into your script might be large or highly dynamic you'll need to define an inputData
mapping via our GUI by providing a key and value.

Mapping inputData
is not available in triggers.
Code steps return a single output
variable, which is an object or array of objects that will be the return value of this Code. You can explicitly return early if you like.
Setting the output to an array of objects will run the subsequent steps multiple times, once for each object in the array.
If your Code step is the Zap's trigger and an empty array is returned, nothing happens. You can think of it like a polling trigger that did not get any results in the HTTP response. This functionality is exclusive to triggers—returning an empty array in a Code by Zapier action does not have the same effect.
There are a few utilities you have access to:
callback(err, output)
(optional): A callback if you need to do asynchronous work—whatever you set to the output data variable is ignored since you provide it directly here. We inspect your Code and make our best guess if you are using callback or not!
Invoking callback(err, output)
tells Zapier that your task is done executing. If you have multiple asynchronous calls, each invoking callback(err, output)
with their desired responses, only the first one to execute will count. Subsequent invocations to callback(err, output)
will be picked up by the next execution of your Zap, but will not affect that task's execution, other than side effects like console.log()
calls. Be sure to carefully manage when you use callback(err, output)
to avoid extremely tricky and confusing bugs!
fetch
: An easy to use HTTP client. Read the documentation here.
console.log
: Super helpful if you want to debug your function. You'll need to test your Zap to see the values. The logs are returned to you in a runtime_meta
added automatically to your output
.
StoreClient
: A built-in utility for storing and retrieving data between Zap runs. Learn more here.
Running your Zap via the dashboard is the canonical way to confirm the behavior you expect. Your Task History will have all relevant details around the Code step's inputData
, output
and logs. The test step in the editor can be used for a tighter feedback loop.
Some common error messages you might find include: