Automation Blog

How to Use AI to Generate JavaScript or Python for a Zapier Code Step

How to prompt ChatGPT, Claude, or any AI assistant to write working JavaScript or Python code for Zapier Code steps — what context to provide, how to frame the request, and how to verify the output before pasting it into your Zap.

ZapierAICode Steps

By Troy Tessalone · · 5 minutes

Automation Guide

A practical field guide from Automation Ace.

How to Use AI to Generate JavaScript or Python for a Zapier Code Step

Zapier Code steps give you the ability to write custom logic — transforming data, calling APIs, building dynamic values — but writing the code from scratch requires JavaScript or Python knowledge that not every Zapier user has. AI assistants like ChatGPT and Claude can write working Code step code in seconds when prompted correctly. The key is giving the AI enough context about Zapier's environment and your specific data to produce code that actually works without modification. This guide covers how to prompt AI for Code step code and what details to include.

What AI Needs to Write Good Zapier Code

An AI assistant generating code for a Zapier Code step needs four things to produce useful output:

  1. The language: JavaScript or Python — specify which you want
  2. The input data fields: What fields are available via inputData (JS) or input_data (Python), and what values they contain
  3. What the code should do: The transformation, calculation, or API call you need
  4. What the output should be: The field names and format of the output object the next Zap step will use

Skipping any of these produces generic code that needs significant editing. Including all four produces code you can paste and run.

Example Prompt: JavaScript Date Calculation

A poorly framed request:

"Write Zapier code to add 30 days to a date."

A well-framed request:

"Write a Zapier JavaScript Code step that takes a date from inputData.start_date (formatted as YYYY-MM-DD, e.g. '2025-03-15') and outputs two fields: due_date as a date 30 days later in YYYY-MM-DD format, and due_date_formatted as a human-readable string like 'April 14, 2025'. The output object should use string values."

The second prompt tells the AI exactly what the input looks like, what format it's in, what the outputs should be named, and what format they should use. The result will be paste-ready.

Example Prompt: Python Data Transformation

"Write a Zapier Python Code step. The input data has: input_data['full_name'] (a string like 'John Smith'), input_data['phone'] (a string like '555-867-5309'), and input_data['tags'] (a comma-separated string like 'vip, enterprise, Q1'). The code should: split the full name into first and last name, strip all non-digit characters from the phone number, split the tags into a list and trim whitespace from each, and return a dict with keys: first_name, last_name, phone_digits, tag_list (as a JSON string of the array), and tag_count (as a string of the count)."

Telling AI About Zapier's Environment

Zapier Code steps run in a specific environment — not a standard Node.js or Python runtime. Including these environment details prevents AI from writing code that uses unavailable features:

For JavaScript Code steps, add to your prompt:

"This runs in Zapier's JavaScript Code step environment. Available globals: fetch (async), URLSearchParams, btoa, atob. The z object is available for z.dehydrateFile(). Node.js built-ins like crypto, querystring, url, buffer, and util are available. async/await is supported. require() supports: lodash, moment, moment-timezone, xml2js, cheerio. Do NOT use fs, child_process, express, or browser APIs. Output must be assigned to the variable output as a plain object with string or number values."

For Python Code steps:

"This runs in Zapier's Python Code step environment. Available libraries: requests, datetime, calendar, json, re, hashlib, hmac, uuid, base64, math. Input data is in input_data dict. The function must return a dict. All values in the return dict should be strings or numbers."

Example Prompt: API Call with fetch

"Write a Zapier JavaScript Code step that makes an authenticated GET request to https://api.example.com/contacts with query parameters email (from inputData.email) and status=active. Set the Authorization header to Bearer {inputData.api_token}. If the response is not OK, throw an error with the status code and response body. Parse the JSON response and output: contact_id (the id field from the first result, or empty string if no results), contact_name (the name field), found as 'true' or 'false', and result_count as a string. Use async/await and URLSearchParams."

How to Verify AI-Generated Code

Before relying on AI-generated Code step code in production:

  1. Read it: Scan for anything that references unavailable APIs (fetch without await, require() for unsupported packages, file system calls)
  2. Test with real data: Paste into a Zapier Code step with real input data values and run a test. Check that output fields match what you specified.
  3. Check edge cases: What happens if the input is empty, null, or in an unexpected format? Add a follow-up prompt: "What if inputData.email is an empty string? Update the code to handle that gracefully."
  4. Ask for comments: See asking AI to document Zapier Code steps with comments for how to get the AI to annotate the code it generates.

Iterating on the Output

If the first response isn't quite right, follow up with specific corrections rather than reprompting from scratch:

  • "The output for tag_count should be a string, not a number. Update that."
  • "Add error handling: if the API returns a 404, output found: 'false' and empty strings for the other fields instead of throwing."
  • "Rewrite this to use Python instead of JavaScript."

AI chat interfaces maintain context in the conversation — each correction refines the previous output rather than starting over.

The prompt pattern that produces the best Code step code every time: state the language, describe the input data fields and their example values, describe what the code should do step by step, and specify the exact output field names and value formats. AI assistants are good at writing code — they just need enough context to write the right code for Zapier's specific environment and your specific data.

For more on the JavaScript environment available in Code steps, see JavaScript libraries in Zapier Code steps. For Python, see Python libraries in Zapier Code steps. For asking AI to debug code that isn't working, see using AI to debug Zapier Code steps. For help building a Code step for a complex integration, talk to Automation Ace.

ZapierAICode Steps

Disclaimer: This article may include links to apps, products, or services. Some links may be affiliate links, which means Automation Ace may earn a commission at no extra cost to you.

Build Better Systems

Ready to automate with confidence?

Share your tools, process, and goals. Automation Ace can design the workflow, integration, AI assist, or code bridge that fits your business.

Start a Project