Skip to content
ConsultEvo

Code by Zapier: When to Use It and How to Design Reliable Code Steps

Use Code by Zapier when a workflow needs custom, testable logic or several dependent transformations that native app actions and Formatter cannot handle cleanly. Use a native app action for an ordinary operation in a connected app, and use Formatter for one straightforward deterministic change, such as changing case or formatting a date.

Code by Zapier runs JavaScript or Python inside a Zap as either a trigger or an action. It is an execution step, not a durable database, a complete integration design, or a guarantee that a downstream write is correct. The examples in this guide are illustrative architectures. Confirm the exact event, fields, permissions, authentication method, and destination operation in the current Zap editor. For broader workflow design, see Zapier automation consulting.

The reliable way to use Code is to define the data contract first, validate both inputs and outputs, bound the work, and give someone ownership of exceptions. That approach matters more than whether the code itself is only a few lines long.

What Code by Zapier does, and when to use it

Code is useful when a workflow needs combined parsing, calculations, conditional rules, custom validation, structured API-response handling, or several dependent transformations in one testable step. It can also return multiple structured items for later Zap steps to process.

  • Choose Formatter for one simple transformation with no custom validation or branching.
  • Choose Code when parsing, calculations, conditional logic, validation, or several dependent transformations belong together.
  • Choose a native app action when the main requirement is an ordinary operation in a connected app.
  • Choose the JavaScript Zapier SDK when JavaScript needs to orchestrate selected connected app actions rather than merely transform data.

Code steps run in a sandbox and have plan-specific runtime, memory, input/output, and rate limits. Current documentation lists Node.js 22 for JavaScript and Python 3.13 for Python. App pairings shown in the Code by Zapier integrations directory are useful for discovery, but they do not prove that a particular event, field, connection, or upsert operation is available in every account.

A Code step is reliable when its inputs, outputs, limits, duplicate behavior, and exception owner are explicit before it is enabled.

Choose a Code trigger, a Code action, or another tool

A Code trigger produces data that can start downstream Zap runs. It cannot map fields from earlier Zap steps, so use it only when the code itself determines or returns the data that starts the workflow. If a Code trigger returns an empty array, it starts no downstream runs.

A Code action receives values mapped from the trigger or an earlier action through its Input Data fields. Treat those fields as an interface between steps. Input Data key names are case-sensitive, and the code should validate the values it receives rather than assuming the editor supplied the intended type.

A Code action can return JSON-serializable data for later steps. When it returns a list of dictionaries, subsequent steps can run once for each returned item. Define the item grain before returning a list. For example, one returned item might represent one source record observed at one retrieval time, not an entire reporting period.

For setup details, see the official guides for JavaScript Code steps and Python Code steps.

Configure a Code step around an input and output contract

For an action, add a Code by Zapier step, choose JavaScript or Python, map the Input Data fields, write or review the code, test it, inspect the returned data, and only then configure and test the downstream action. Editor labels can change. The current AI-generation flow describes generating code, adding it to the step, and testing it.

Before writing code, define what the step accepts. This illustrative input contract is intentionally small:

{
  "source_id": "Required string identifying the source record",
  "event_type": "Required string from an agreed set of event types",
  "raw_value": "Optional string to normalize",
  "source_updated_at": "Required ISO 8601 timestamp"
}

Specify required and optional fields, expected types, allowed values, and the response to missing or malformed data. Do not replace invalid input with a plausible-looking default. The following JavaScript is an editorial example, not a Zapier-prescribed schema:

const sourceId = inputData.source_id;
const rawValue = inputData.raw_value;
const errors = [];

if (typeof sourceId !== "string" || !sourceId.trim()) {
  errors.push("source_id is required");
}
if (rawValue != null && typeof rawValue !== "string") {
  errors.push("raw_value must be a string");
}

const normalizedValue =
  typeof rawValue === "string" ? rawValue.trim().toLowerCase() : null;

return {
  status: errors.length ? "rejected" : "normalized",
  source_id: typeof sourceId === "string" ? sourceId.trim() : null,
  normalized_value: errors.length ? null : normalizedValue,
  validation_errors: errors,
  processed_at_utc: new Date().toISOString()
};

The output contract names a status, stable source identifier, normalized value, validation errors, and processing time. Downstream steps should map named fields from the tested output, not depend on an undocumented positional order or an unchecked free-text result.

01Define the contractName each input, type, required status, output field, and item grain. The workflow owner approves the definitions.
02Select the stepChoose a trigger only when code supplies the starting data. Otherwise use the existing event, map its fields into a Code action, and select JavaScript or Python.
03Implement and testReview or write the logic, test normal and edge inputs, and inspect returned fields, statuses, and errors.
04Map the destinationUse tested, named output fields in the destination action and verify its required fields, record identity, and unchanged-value behavior.
05Assign exceptionsName the person or team that reviews rejected records and decides whether to correct, retry, replay, or stop them.

Zapier’s AI code generation feature is in beta. It can generate JavaScript or Python from a natural-language description, but generated code is not evidence of correctness, security, or production readiness. Review it against the same contract as hand-written code, inspect credential handling, and test it with fixed fixtures before allowing consequential writes. See the official AI Code step guide.

Three illustrative workflow designs

The following patterns are not importable templates or verified end-to-end configurations. They show how to connect a source event, Code step, validation gate, destination, and exception route. Confirm the exact trigger, fields, authentication, permissions, and write operation in the current editor.

Workflow Code or AI role Validation gate Destination and fallback
Scheduled API observations
A schedule starts a Code action that requests and parses a bounded response.
Use deterministic parsing for a known response schema. Return status, source_id, observed_at_utc, run_id, value, and validation_errors. AI is unnecessary for stable structured data. Check HTTP status and response shape, reject missing IDs, bound pagination and payload size, and preserve the retrieval timestamp. One row represents one source entity at one retrieval time. Write one observation to a spreadsheet if the required action is available. Use a stable destination key or atomic upsert where supported. An API owner resolves authentication or schema failures; a data operator reviews rejected rows.
Slack message normalization
A selected Slack message event maps channel, message, author, thread, event type, and raw text into Code.
Remove stable text patterns or extract structured values deterministically. If classification is genuinely unstructured, constrain AI to an allowed label set and return the label with the source event ID. Handle bot and system messages deliberately, distinguish new messages from edits and replies, validate required fields and destination length, and preserve raw_text separately from normalized_text. Create or update a destination record using the stable message or event identity. A content reviewer handles ambiguous messages; the workflow owner fixes parsing and mapping defects.
Timestamp normalization
A record-change event maps a record ID, raw timestamp, and source timezone or offset into Code.
Use deterministic parsing. Return status, record_id, original_timestamp, normalized_timestamp_utc, and validation_errors. Require an explicit timezone or UTC offset, reject ambiguous local times, preserve the original value, and skip the write when the normalized value has not changed. Update the table record by record ID if the required event and action exist. The record owner resolves timezone problems; the workflow owner investigates repeat-trigger loops.

Keep the grain visible in the destination. An API observation is not a reporting-period aggregate. A Slack record represents one message event, not one channel. A timestamp update targets one record, not a non-unique display name. Measure valid-output rate, duplicate rate, exception volume, and time to resolve exceptions against your own baseline.

Concurrency matters

A search followed by create is not an atomic upsert. Two concurrent Zap runs can both find no match before either creates a record. For high-integrity writes, prefer a destination-enforced unique key, transactional upsert, native idempotency key, or another atomic write where available. StoreClient can hold lightweight markers, but it is not documented as a transactional lock.

Runtime, task use, and payload limits affect the design

Code by Zapier has plan-specific standard runtimes, not a universal two-minute allowance. Current documentation lists 1 second on Free, 30 seconds on Professional and Team, and 2 minutes on Enterprise. Trial accounts follow the plan being trialed. The documented plan tiers list 512 MB of memory.

Eligible paid plans can extend Code actions up to 10 minutes. Extended runtime does not apply to Code triggers, and Free plans cannot use it. Billing for extended runtime began June 15, 2026. Each Code action uses one base task, and time beyond the standard runtime uses one additional task per 30-second block, with partial blocks rounded up.

Code steps have a documented 6 MB input/output limit, and a Code action can return no more than 250 items. Code-step rate limits are plan-dependent: current documentation lists 10 requests per 60 seconds for Free, 75 per 10 seconds for Trial, and 225 per 10 seconds for Professional, Team, and Enterprise. Excessive traffic can hold Zap runs until the limit resets. Check the current Code overview, extended-runtime rules, usage measurement, and rate-limit guide before estimating production work.

Bound loops, pages, response size, and returned data. Estimate maximum records and payload size before adding pagination. If normal runs approach a plan limit, reduce the batch, use a supported incremental design, add appropriate delay or flood protection, or choose an execution environment suited to the workload. A longer timeout does not make unbounded work reliable.

Use the SDK, StoreClient, and AI for distinct jobs

The Zapier SDK is currently available in JavaScript Code steps, not Python, and is in open beta. The step must enable the @zapier/zapier-sdk package and select the app connections it may use. Only the Zap owner can add those SDK connections. Documented action types include read, write, and search.

Use the SDK when JavaScript needs to orchestrate selected connected app actions or authenticated calls through Zapier infrastructure. Confirm each action’s required inputs, connection ownership, account scope, permissions, pagination behavior, and retry behavior. Do not assume that a sequence of app actions is transactional or that SDK retries provide business-level idempotency. Record IDs after successful writes and design a recoverable path for partial completion. Raw API calls have separate governance considerations from selected SDK connections.

StoreClient is available in JavaScript and Python for lightweight cross-run state, such as counters and processed-ID markers. A UUID4 secret is required. StoreClient can support a deduplication design, but it does not replace a database uniqueness constraint or establish race-safe locking.

AI generation can draft JavaScript or Python from a natural-language description. Give it explicit input types, output fields, and failure behavior, then review the result, test edge cases, and validate outputs before allowing customer, finance, CRM, permission, or deletion writes.

Test failure paths, prevent duplicate writes, and assign an owner

A happy-path test proves only that one input produced an output. Test a valid record, missing required input, malformed input, boundary values, unexpected response shape, and downstream failure. A timeout or temporary service failure may be retryable. A missing identifier, ambiguous timestamp, or invalid destination value usually needs correction or review before replay.

For CRM writes, preserve the source identifier and provenance, validate destination field types, and compare the proposed value with the current value before updating. If classification is involved, check the result against an allowed-value set and route uncertain or high-impact changes for human approval. A named reviewer should own rejected or ambiguous records and decide whether a corrected event can be replayed. Teams designing these controls across connected customer systems can use CRM systems consulting.

Go-live checks
  • Required input fields, types, output names, and row grain are documented.
  • Missing, malformed, boundary, unexpected, and downstream-failure cases have been tested.
  • Duplicate behavior uses a stable identity and a destination-enforced unique key, atomic upsert, or suitable idempotency mechanism where concurrency is possible.
  • Connection scope, account permissions, authentication handling, and raw API governance are understood.
  • The destination action, record identity, unchanged-value behavior, and partial-failure path have been tested.
  • A named exception owner and a retry, correction, or replay policy are in place.

Enable the Zap only when the output contract, duplicate behavior, connection scope, failure route, and exception owner are clear. That makes Code by Zapier a controlled part of the workflow rather than an opaque transformation between applications.