codefmt — back to formatter

zapier code formatter & beautifier

code by zapier js actions run in an async context with `inputData` (mapped fields), pre-provided `fetch`, and either `return` or `callback(err, output)` for results. the node stdlib is available; the only npm package is `@zapier/zapier-sdk` (toggle it on in the editor's Packages panel).

code by zapier lets you write custom javascript or python to transform data, make API requests, and connect services. your javascript runs inside an async function with access to inputData (mapped fields), output (assignable result), fetch, callback, and console.

standard formatters and linters fail on zapier code because it uses top-level await and bare return statements. codefmt wraps your code in the correct async function before formatting, then strips it back, so you get clean, beautifully formatted code that works directly in zapier.

codefmt also supports zapier python code with input_data, output, StoreClient, and requests as registered globals. the lint plugin catches common mistakes in both languages before you publish your zap.

frequently asked questions

why does prettier fail on my zapier code?

zapier code runs inside an invisible async function wrapper. this means top-level await and bare return statements are valid inside zapier, but invalid as standalone javascript. prettier tries to parse your code as a complete program and fails. codefmt handles this automatically by wrapping your code before formatting and stripping the wrapper afterward. it also detects zapier's newer sdk-in-code form (top-level `import` and `export default async function main(...)`) and parses it at module scope so the same prettier-style parse error doesn't happen there either.

what globals are available in code by zapier?

code by zapier javascript injects inputData (your mapped input fields), output (assignable result), fetch (preinstalled, no require needed), callback for async completion, and console. the node standard library and fetch are available; the only npm package you can import is @zapier/zapier-sdk (enable it via the Packages panel in the code editor). codefmt recognizes all of these and won't flag them as undefined.

can I use async/await in zapier code?

yes. zapier wraps your code in an async function, so top-level await works directly. you can also use return to send data to the next step, or call callback(err, output) for classic async-completion. codefmt preserves your async/await patterns during formatting.

can I use lodash or other npm packages in zapier code?

not for general npm modules — lodash, axios, and moment are not available and cannot be required. the one exception is @zapier/zapier-sdk, which you enable via the Packages panel in the code editor; it lets you call your connected zapier app actions and make authenticated http requests through zapier. for anything else you either inline the logic or move to a different platform.

what globals are available in zapier python code?

zapier python code injects input_data (mapped input fields), output (assignable result dict), StoreClient (class for zapier's key-value store: store = StoreClient('secret')), and requests (preinstalled http library). codefmt formats python code with ruff and recognizes all of these globals.