How does Code mode work?
Each API call pane in Zapier visual builder includes a code mode toggle
The Zapier visual builder includes a form to add API endpoint URLs and choose the API call type, then automatically includes any authentication details and input form data with the API call. You can also set any custom options your API may need, including custom URL params, HTTP headers, and request body items. Zapier then parses JSON-encoded responses into individual output fields to use in subsequent Zap steps.
This is the best way to set up most API calls and options in Zapier integration authentication, triggers, and actions.
Remember: Code mode is a toggle. Code mode and Form mode are saved separately; changes to one do not affect the other. The settings in the currently visible editor are the ones Zapier uses in your integration.
z.object for Zapier specific features, including
z.console to write to the console log,
z.JSON to parse JSON,
z.errors to take action on errors, and more. Check Zapier’s CLI Z Object docs for details.
Additionally, use Zapier bundles to access auth data, data from user input forms, request data, and more. Learn more in our Zapier bundle docs.
Note: If you were familiar with our legacy Web Builder environment, we used to include several 3rd party libraries, like lodash, and made them available on the z object. Those libraries are not included in the new version of the UI tool. If you need access to additional modules you can easily move your project to the Zapier CLI and take advantage of npm to bring in any additional libraries you need.
Note that, in Code mode you can import from Node’s standard library with
z.require, for example,
z.require('crypto'). We strongly recommend you keep it simple when coding in the UI tool. The CLI is much better suited to building and testing complex code. And be sure you know what you’re doing - we can’t guarantee that everything you might use from the standard library will be supported in our platform’s runtime.
There is a time limit of 30 seconds for each trigger and action, so keep your custom code as light and quick as feasible. If code takes longer than 30 seconds to run, it will time out, and users’ Zaps will not be successful.
Do note that changes are not saved automatically. Once you have added the code you want, click Save & Continue to add the changes to your integration.
Switch back to form mode to use the form mode settings instead of your custom code
Once you switch to code mode, Zapier uses your custom code for that API call, and does not use the data you previously entered in the form.
If you wish to switch back to the form mode, click the Switch to Form Mode button to see the form options as they were when you first switched to code mode. Zapier will save the code you entered, but will not convert it back to the form mode or use the custom code in your live integration.
You may switch back to code mode again—though this time, Zapier will show the last saved version of your code, and will not copy any changes from your API call form to the code.
Here are some resources that will be helpful when using the Code Mode:
- HTTP Request Options
- HTTP Response Object
- HTTP Requests
- Dynamic Dropdowns
- Return Types for Triggers, actions and searches
- The Bundle Object
- Accessing Environment Variables
- When to use placeholders or curlies vs template literals
- Error Handling
- Error Response Handling
- Schema Docs: 11.3.0, 10.2.0, 9.7.3
Is my Zapier integration using the Form or Code mode settings?
Zapier uses the currently visible option when running each part of your integration. If the form mode is visible for an API call in an integration’s authentication, trigger, or action settings, that Zapier integration is using the data from form mode. If the code mode is visible for an API call, Zapier is using the code instead to turn that part of the integration.
To check which mode and settings Zapier is using for each API call, open that part of your Zapier integration and visually check to see if the form or code mode is visible.
For this request, wrap the response with an array instead of the default
return results, to have Zapier return an array of issues.
Remember: “Code Mode” is a toggle; if you switch back to Form mode your code will be ignored! Learn more.
Now, retest the request and it should run successfully.