Code steps can be used as both triggers and actions.
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.
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’(/help/line-items/) instead, you can add
line_items as the parent key for the output.
"line_items" : [
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.
There are a few utilities you have access to in Code steps:
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
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
output and logs. The test step in the editor can be used for a tighter feedback loop.
Some common error messages you might encounter include:
If you're using a linter, you can safely ignore warnings about unused variables for
callback. Those are provided for your convenience, but you don't need to use them. If you see something else listed, you may need to debug your code.