Before you begin
- Complete the quick start. This guide uses the same project, login, and
ZAPIER_STABILITY=betasetting. - A Google Sheet with the column headings
Name,Email, andSigned upin row 1.
1. Write a workflow that uses your apps
Replace the contents ofworkflow.ts with this workflow:
workflow.ts
What each part of the code does
What each part of the code does
zapier.runAction()runs an app action.connectionnames a connection alias, such assheets, that you map to a real connection in the next step.COL$AtoCOL$Care the Google Sheets action’s fields for columns A to C, andworksheet: "0"is the first sheet.ctx.step({ ... })is the object form of a step. Put the function inrun, next to retry settings such asmaxAttemptsandretryDelaySeconds.ctx.wait()pauses the workflow for a number of seconds without holding a server open.- The SDK client sits at the top of the file. If you create it inside
run, the workflow stops with aDeterminismViolationerror.
Use a different app
Use a different app
You can swap Gmail or Google Sheets for any app on Zapier. For each step you change, use the Zapier SDK CLI to find three values: the app, the action, and the action’s input fields.
-
Find the app’s key:
-
List the app’s actions. Use
keyasactionandaction_typeasactionType: -
List the action’s input fields. Use each
keyininputs:For the fields as JSON Schema, which coding agents read more reliably, runget-action-input-fields-schemawith the same values.
zapier.fetch(), using your connection. Some Enterprise accounts block these calls. For details, check Make custom API calls with fetch.2. Point the workflow at your apps
The workflow needs a Gmail connection, a Google Sheets connection, and the ID of your sheet. Use the Zapier SDK CLI to find your connections.-
List your connections for each app and copy the
idof the one to use: -
Create a file named
.zapierrcthat maps each alias in the code to a connection ID:.zapierrc -
Copy your spreadsheet ID from the sheet’s URL. It is the part between
/d/and/edit. ReplaceYOUR_SPREADSHEET_IDinworkflow.tswith it.
Connect an app for the first time
Connect an app for the first time
If
list-connections returns nothing for an app, you have no connection to it yet. Connect the app in Zapier, then run list-connections again.To start from your terminal instead, get a link to connect the app and open it in the browser where you are logged in to Zapier:3. Test it on your machine
Create a file namedtest-onboarding.ts. Use your own email address so the emails come to you:
test-onboarding.ts
done: false, because the workflow paused at the wait.
After the 5-second wait ends, create resume-onboarding.ts with the executionId from the output, and run it:
resume-onboarding.ts
done: true with the result.
Why the run pauses, and how resuming works
Why the run pauses, and how resuming works
On your machine, a paused workflow continues only when you call it again with its When you resume, the steps that already finished do not run again, so you get no second row and no second welcome email. On Zapier, waits end on their own, so you do not need to resume.
executionId. The first run returns:Response
4. Deploy it with your connections
Create a Next Gen Zap for the workflow and save its ID:.zapierrc works on your machine only, so pass the same connection IDs in --connections. Zapier installs @zapier/zapier-sdk and zod for you. In production, set exact versions so each publish installs the same code. To set them, check Choose package versions:
connections.
Add a trigger
Add a trigger
To run the Next Gen Zap when something happens in an app, such as a new form response, publish with
--trigger instead of --manual. Use the Zapier SDK CLI to find each value:-
List the app’s triggers. Use
keyasactionandapp_keyasselectedApi: -
List the trigger’s input fields. Use each
keyinparams: -
Find the connection to use, the same way as in step 2. Its
idis theauthenticationId. -
Publish with the trigger, and leave out
--manual:
--trigger and --manual. A trigger that needs no connection, such as one in Schedule by Zapier, does not need authenticationId.The Next Gen Zap runs once for each new trigger record, such as each new form response, and run receives that record as input. inputSchema sets the type of input in your code, but Zapier does not check the record against it. Parse the record in run before you use its fields. You can still run the Next Gen Zap manually. For manual runs, Zapier uses inputSchema to find the input fields.5. Run it on Zapier
Start the Next Gen Zap with your own email address:status: "finished" with output set to { "savedTo": "Sheet1", "emailsSent": 2 }.
You can also start the Next Gen Zap from the Workflow Manager. If it uses apps, the Workflow Manager asks you to confirm the app connections before the run starts.
If a step fails, Zapier retries it, so status can stay started for a few minutes before it changes to failed. Zapier also emails you, and the agent in the Workflow Manager explains the cause and suggests a fix.
Example of a failed run
Example of a failed run
If the version has no connections, the
save-customer step fails:Response
error.message names the step. error.details.cause.message gives the reason. To fix this example, publish again with --connections. You cannot change a published version, so each fix publishes a new one.Next steps
CLI reference
Every option for
publish-workflow-version, including --trigger.How Next Gen Zaps in code work
Learn how steps, waits, callbacks, and replays work.