Code steps allow Zaps to run small snippets of Python or JavaScript. This tutorial is for JavaScript code steps, but you can also learn how to use Python code in your Zaps.
Code steps can be used as both triggers and actions.
JavaScript is an advanced programming language.
- If you're not familiar with JavaScript, you should ask a developer for help.
- If you require assistance with how Code by Zapier processes code (not writing or debugging), contact Support based on your plan.
- For additional resources, visit the Zapier Community's Code resources.
The JavaScript environment
The environment running is Node.js 18. Your script is sandboxed and can only run for a limited amount of time and within a limited amount of memory—the exact limits depend on the plan you're using.
- AWS does not prevent deprecated Node run times from running.
- Dates and times in Code actions use the UTC timezone, even if a different one is set for the account or the Zap.
Input data for Code steps
You can access data from previous steps via the inputData dictionary variable in your code step. The amount of data that may feed into your script may be large or dynamic. To address this, you must define an inputData mapping by providing a key and value in Zapier's GUI.
You cannot map fields from previous Zap steps to the Code field. You must use the Input Data dictionary.
You can create a key/value pair in the Input Data field for each mapped field you want to use in your code.
In Javascript, you can access the inputData dictionary variable values by using the inputData.keyName or inputData["keyName"] notation. Key names are case-sensitive and must be an exact match when referenced.
In the example below, the key name is "defineName" and the value is supplied by the Name field that's mapped from a previous step. In this example, the value supplied by the mapped Name field is "Jane".

It's not possible to map inputData in Code by Zapier triggers.
Output data from Code steps
Code steps return a single output variable, which is an object or array of objects that will be the result of this step. You can explicitly return early.
If the output is an array of objects, subsequent steps will run multiple times, once for each object in the array.
[
{
"product_id": 123,
"name": "world",
"price": 5.50
},
{
"product_id": 234,
"name": "planet",
"price": 11.00
}
]In this example, each object in the array is returned separately. Subsequent actions will run once for each object.


To return the whole array as line items instead, you can add line_items as the parent key for the output.
{
"first_name": "Zap",
"last_name": "Zaplar",
"invoice_id": 123456,
"total_price": 55.50,
"line_items": [
{
"product_id": 123,
"name": "world",
"price": 5.50
},
{
"product_id": 234,
"name": "planet",
"price": 11.00
}
]
}In this example, the array is returned as a set of line items. Any subsequent actions will only run once.

If you use Code by Zapier as the Zap's trigger and an empty array is returned, nothing will happen. The behavior will be similar to a polling trigger that did not get any results in the HTTP response. This functionality is exclusive to triggers.
Utilities in Code steps
There are a few utilities you have access to in Code steps:
-
fetch: an easy-to-use HTTP client. -
console.log: this utility allows you to debug your function. You'll need to test your Zap to see the values. The logs are returned in aruntime_metaadded automatically to theoutput. -
StoreClient: a built-in utility for storing and retrieving data between Zap runs. - (Optional)
callback(err, output): a callback if you need to do asynchronous work—whatever you set to the output data variable is ignored since it's provided directly here. The Zap will inspect the code and make a best guess as to whether it's using a 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.
Add a Code step to your Zap
1. Add a code trigger
- In the Zap editor, click the Trigger step.
- Search for and select Code by Zapier. The Code editor opens automatically.
- Click the Code dropdown menu and select JavaScript.
2. Write your code
- In the Code editor, enter your JavaScript code.
If you prefer not to use the Code editor, click the Regular editor icon to switch to the standard editor view.
3. Test your code trigger
- Click Run Code to test your code.
- The Output Data panel appears on the left so you can review if your code worked as expected.
If your code is valid, the step shows it was successful and displays the data. Once the trigger is set up, you can continue to add your action step.
1. Add a code action
The Code action step allows you to write code that interacts with data coming from the trigger or a previous action step.
- In the Zap editor, click the + icon to add a new step.
- Search for and select Code by Zapier. The Code editor opens automatically.
- Click the Code dropdown menu and select JavaScript.
2. Write your code
- In the Code editor, enter your JavaScript code.
- You can also define data fields to be provided to the code as strings with the Input Data fields. Provide a key and a value for each field.
If you prefer not to use the Code editor, click the Regular editor icon to switch to the standard editor view.
3. Test your code action
- Click Run Code to test your code.
- The Output Data panel appears on the left so you can review if your code worked as expected.
- If your code is valid, the step shows it was successful and displays the data.
You can generate code steps using AI.
Testing and debugging Code steps
Running your Zap via the dashboard is the canonical way to confirm the behavior you expect. Your Zap 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.
Limitations with Code steps
- The environment in which your Code steps run (AWS Lambda) has an I/O limit of 6 MB. The total size of the code and the data processed by the Code step cannot exceed that. If you're hitting this error, try to limit the amount of data returned from your function. For instance, do not return an entire JSON structure, just the keys you need.
- You cannot require external libraries, or install or import libraries commonly referred to as "npm modules". Only the standard node.js library and the
fetchpackage are available in the Code by Zapier app.fetchis already included in the namespace. - There are different Code rate limits and throttling, depending on what Zapier plan you're on. Your Zap will error if it exceeds these limits.
- If you need to make more than 2 HTTP requests or make authenticated HTTP requests, Zapier recommends creating a custom app on the Zapier platform.
- In a Zap, if you add or edit a Code step that includes authentication, your draft will be saved, but you will not be able to publish edits unless you are the Zap owner.