Automation Answers

Why Is My Zapier Code Step Returning Undefined?

A Zapier Code step returns empty or undefined output when output is never set, a promise is not awaited, or an inputData key is misnamed or blank.

By Automation Ace Editorial Team · Reviewed for technical accuracy by Troy Tessalone · Published · Updated

Short answer

Why Is My Zapier Code Step Returning Undefined?

A Code by Zapier step returns undefined or empty fields when the code never sets output or returns early. It also happens when an async call isn't awaited, or when the code reads an inputData key that doesn't exist or is blank in this run. Log the inputs, await every promise, and always return a plain object with the keys later steps need.

Common causes

  • The code builds a result but never assigns it to output or returns it.
  • A fetch or other promise isn't awaited, so the step finishes before the value exists.
  • The key in code (inputData.email) doesn't match the Input Data name in the editor (Email). Keys are case-sensitive.
  • The mapped field is blank in this run, or arrives as a string you treat as a number or array.
  • A property you return is undefined, so it never shows up as a field for later steps.

Diagnostic steps

  1. Temporarily return the raw inputs, for example output = {debug: JSON.stringify(inputData)}, and test the step.
  2. Check that every key used in code exists in the Input Data list with exactly the same spelling.
  3. Put await before every fetch and .json() call, and check response.ok before reading the body.
  4. Convert types on purpose: every inputData value is a string, so use Number(), JSON.parse(), or split() as needed.
  5. Return defaults instead of undefined, such as output = {total: total ?? 0}, so later steps always get a field.

Example

A step calls an API with fetch(url).then(r => r.json()) but assigns output outside the callback. The step ends before the request finishes and returns nothing. Rewriting it as const data = await (await fetch(url)).json(); output = {id: data.id}; returns the ID.

Caveats

Test data can include fields that are blank in live runs, so test with a realistic record. Code steps have plan-based runtime and memory limits, so move long-running or heavy jobs to an external function.