Skip to main content
Write a workflow in TypeScript, test it on your machine, and run it on Zapier as a Next Gen Zap in code. A Next Gen Zap is an automated workflow that runs on Zapier. To build a Next Gen Zap without code, ask your MCP client to build one for you.
To have your coding agent build it, give it this prompt:
The commands and SDK methods that create, publish, and run Next Gen Zaps are in the beta tier. They are ready to build against, but their shape may still change in a minor release. @zapier/zapier-durable is pre-1.0.

Before you begin

1. Run the CLI init command

Run init where you want the project folder:
The init command:
  1. Creates the my-first-zap folder with a package.json, a tsconfig.json, and a starter app in src/index.ts.
  2. Asks to install the Zapier SDK, the Zapier CLI, TypeScript, and tsx.
  3. Asks to log you in to Zapier. A browser window opens for you to approve the login.
  4. Asks to run a sample program. You do not need it, so you can answer no.
If you are already logged in, the login step stops with “Already logged in” and the summary shows “Setup interrupted”. Your files and packages are already in place, so you can continue. Then go to the project folder and add the workflow packages. @zapier/zapier-durable defines the workflow. Zod is a TypeScript library for describing the shape of data, and the workflow uses it to define its input.

2. Write your first workflow

In the project folder, create a file named workflow.ts. The example that follows defines a workflow with no trigger, so it runs only when you start it. It has three steps: one builds a greeting from the input, one formats it with Formatter by Zapier, and one records the time.
workflow.ts
Zapier runs this file when you publish, so keep the name workflow.ts and export the defineDurable() call as the default export. The format-greeting step runs an action in Formatter by Zapier, a Zapier app that needs no app account or connection. zapier.runAction() works the same way for any of the apps on Zapier.
  • If the file is missing, Zapier rejects the version with “No workflow entry point found”. workflow.mts, .js, .mjs, .cjs, and .cts also work.
  • Zapier reads inputSchema to find the Next Gen Zap’s input fields, so keep it in this file.
  • Your workflow checks input against inputSchema only when your own code calls it with input, such as in a local test. Zapier does not check the input of the runs it starts.
  • For every field defineDurable() accepts, read the package README on GitHub.

3. Test it on your machine

Create a file named test-locally.ts that calls the workflow with sample input:
test-locally.ts
Run it:
The output includes done: true, the workflow’s result, and the ID of this execution:
Response
A local run keeps its journal on disk in ~/.config/zapier-sdk/durable. The Formatter step runs through your Zapier login, but the workflow itself is not on Zapier yet.
The SDK could not find your Zapier login. Run the test from the project folder that init created, which has the Zapier CLI installed. If you set the project up another way, install the CLI in it and log in:

4. Deploy it to Zapier

Before you deploy, check your code. validate-workflow checks workflow.ts without publishing anything, so you can also run it in CI. It checks connections and triggers only if you pass them:
If your code passes, issues is empty:
Response
Each problem appears in issues with a message and the line it is on. The command exits with code 0 even when issues lists errors, so in CI, fail the job when issues is not empty. For example, add | jq -e '.data.issues == []' to the end of the command. Create an empty Next Gen Zap, then publish workflow.ts as its first version. Publishing turns the Next Gen Zap on. It has no trigger, so --manual marks it as a Next Gen Zap that runs only when you start it.
The CLI saves the Next Gen Zap’s details in zap.json and its ID in WORKFLOW_ID. If you use TypeScript, set WORKFLOW_ID to the printed ID before you run the next step: export WORKFLOW_ID=YOUR_ZAP_ID. The publish response includes the new version’s id. Zapier installs @zapier/zapier-sdk and zod for you, so you do not pass --dependencies. Formatter needs no connection, so you do not pass --connections. In production, set exact versions so each publish installs the same code. To set them, check “Choose package versions” below.
ZAPIER_STABILITY=beta turns on the CLI’s beta commands for your terminal session. You can pass --stability beta to each command instead. Without it, the CLI stops with error: unknown command 'create-workflow', and WORKFLOW_ID is empty, so the publish command fails too.The TypeScript example imports from @zapier/zapier-sdk/beta and needs no setting. Each beta command and method prints a warning that it is in the beta tier. The warning does not affect the result.
  • Zapier installs zod unless you add your own version to --dependencies. It also installs @zapier/zapier-sdk when your workflow imports it.
  • Without --zapier-durable-version, Zapier uses its default version of @zapier/zapier-durable. Set the version with this flag, not --dependencies.
  • For @zapier/zapier-durable and @zapier/zapier-sdk, latest resolves when you publish to the newest release that has been on npm for at least 24 hours. Zapier stores the exact version with the published version, so its runs always use the same code.
  • If your workflow imports other npm packages, add them to --dependencies with exact versions.
  • In production and CI, set exact versions for every package, so that each publish installs the same code.

5. Run your Next Gen Zap

Start the Next Gen Zap with sample input. The command waits up to 60 seconds for the run to finish and then returns it.
When the run succeeds, status is finished and output holds the value your run function returned:
Response
If status is still started when the command returns, the run is still going, for example while a step retries. Check it again later with the run’s id:
If status is failed, error.message names the step that failed. Fix workflow.ts, then publish a new version and run it again.

6. Check your Next Gen Zap in the Workflow Manager

Open the Workflow Manager link from zap.json:
  • Each step is a card, titled with the step’s name.
  • The code of the published version is read-only. To change it, select Edit Zap.
  • Agentic management is on by default. When a run fails, the agent investigates and suggests a fix.
Each time you publish, Zapier stores a new version and runs that version from then on.
Your local workflow.ts and the Next Gen Zap do not sync. Publishing sends a copy of your code to Zapier, and edits in the Workflow Manager stay on Zapier. Before you edit locally, download the latest published code with the version’s id:
To download unpublished edits from the Workflow Manager, use get-workflow-draft with the draft’s ID from list-workflow-drafts.
To change a Next Gen Zap without affecting its live runs, work in a draft:
  1. create-workflow-draft copies the live version into a new draft.
  2. update-workflow-draft saves your new workflow.ts to the draft.
  3. run-workflow-draft runs the draft on Zapier. Pass the draft’s ID and its draft_revision from the last create or update response. Draft runs do not use tasks.
  4. publish-workflow-draft makes the draft the new live version.
For each command’s options, check the CLI reference.
The Next Gen Zap has an open draft with unpublished edits, or a draft copied from an older version. If you publish directly, that draft could later overwrite your new version. To fix it, choose one:
  • Publish the draft with publish-workflow-draft.
  • Delete the draft with discard-workflow-draft.
  • Publish anyway with --ignore-open-drafts.
A draft with no edits does not block publishing while it is copied from the current live version.

Next steps

Call apps from a Next Gen Zap

Use apps that need a connection, such as Gmail and Google Sheets.

Add a trigger

Run the Next Gen Zap when something happens in an app, such as a new form response.

Run on your own servers

Keep your code on your servers while Zapier stores the journal and resumes executions.

How Next Gen Zaps in code work

Learn how steps, waits, callbacks, and replays work.
Last modified on December 1, 2026