> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zapier.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Run workflows on your own servers

> Run @zapier/zapier-durable workflows on your own servers in push mode: Zapier keeps the journal and sends a request to your notification URL when each execution is ready to resume.

Run your `defineDurable()` code on your own servers when it needs to reach systems that only your servers can, such as a database on your private network. Your servers run the code. Zapier saves each step's result and tells your servers when to continue, so you do not need to build your own storage or scheduler for long waits. This is called push mode.

> [!NOTE]
>
> Push mode is in beta, with these known limits:
>
> * Requests to your notification URL carry no credentials. Resume only executions your app started.
> * `RestClient` does not refresh an expired token. Create a new client each time you start or resume an execution.
> * You cannot check push-mode executions in the Workflow Manager or with a CLI command.

## Before you begin

* A [`defineDurable()` workflow](https://docs.zapier.com/sdk/build-a-zap-in-code).
* `@zapier/zapier-durable` and `@zapier/zapier-sdk` installed in your app.
* A Zapier login: run `npx zapier-sdk login` or set `ZAPIER_CREDENTIALS`. In production, use [client credentials](https://docs.zapier.com/sdk/deploy.md).
* A public HTTPS URL that accepts POST requests, such as `https://my-app.example.com/durable/resume`.
* Somewhere to store execution IDs, such as a database table.

## Set up push mode

1. Create a function that returns a `RestClient` pointed at your notification URL. Call it each time you start or resume an execution:

   ```typescript Create the client theme={null}
   import { RestClient } from "@zapier/zapier-durable";
   import { resolveAuthToken } from "@zapier/zapier-sdk";

   // RestClient keeps the token it was created with and does not refresh it.
   // resolveAuthToken() reads the token from `npx zapier-sdk login` or
   // ZAPIER_CREDENTIALS, and refreshes it when it expires.
   async function createClient() {
     const token = await resolveAuthToken();
     return new RestClient({
       token: token!,
       notificationUrl: "https://my-app.example.com/durable/resume", // YOUR_NOTIFICATION_URL
     });
   }
   ```

2. Start an execution with that client, and save its ID. Replace `myWorkflow` with your workflow's name:

   ```typescript Start an execution theme={null}
   const first = await myWorkflow({ userId: "u_123" }, { client: await createClient() });

   // executionId: the ID Zapier sends back when it is time to resume.
   // myExecutions stands for the store where your app keeps the IDs it started.
   await myExecutions.add(first.executionId!);
   ```

   The execution runs until it finishes or reaches a wait or callback. If it suspends, Zapier keeps its journal.

3. Add a POST handler at your notification URL that checks the request and queues the execution to resume:

   ```typescript Handle the resume request theme={null}
   // In the handler for POST /durable/resume:
   let execution_id: unknown;
   try {
     ({ execution_id } = JSON.parse(body));
   } catch {
     return; // Reply with a 2xx status and do nothing.
   }

   // The request carries no credentials. Resume only IDs your app recorded.
   if (
     typeof execution_id !== "string" ||
     !(await myExecutions.has(execution_id))
   ) {
     return; // Reply with a 2xx status and do nothing.
   }

   // Zapier waits only 30 seconds for a reply, so resume in the background.
   // resumeQueue stands for your job queue or background worker.
   await resumeQueue.add(execution_id);
   ```

4. In a background worker, resume each queued execution:

   ```typescript Resume in a background worker theme={null}
   // For each execution ID your worker takes from resumeQueue:
   await myWorkflow(executionId, { client: await createClient() });
   ```

   When a wait ends or a callback arrives, Zapier sends `{ "execution_id": "..." }` to your notification URL, and your worker resumes the execution from where it stopped.

5. Reply to every request from Zapier with a 2xx status.

> [!WARNING]
>
> Resume an execution only if your app started it. Requests to your notification URL carry no credentials, so treat each one as a signal only.

## How Zapier delivers resume requests

| Rule | What to do |
| - | - |
| The URL must be public. | Use a URL that Zapier can reach from the internet. |
| Zapier does not follow redirects. | Point `notificationUrl` at the final URL. |
| A request can arrive up to a minute after the wait ends. | Do not rely on exact timing. |
| Zapier waits 30 seconds for a reply. A timeout counts as a failed delivery. | Reply with a 2xx status right away, and resume the execution in a background worker. |
| After 5 failed deliveries in a row, Zapier fails the execution. | Reply with a 2xx status, even when you ignore the request. |
| A `410` reply stops requests for that execution, but does not end it. A callback that arrives later can start the requests again. | Do not use `410` to stop an execution. |

## Verify the result

Check that your handler resumes executions:

1. Start an execution that calls `ctx.wait()` for a short time, such as 60 seconds.
2. Wait for Zapier to send a request to your notification URL.
3. Confirm the request reached your handler and that the resumed call to `myWorkflow()` returns `done: true`.

> [accordion] Run without a Zapier account
>
> You can also run `defineDurable()` code [fully on your own](https://github.com/zapier/durable#fully-on-your-own). Your process keeps the journal and decides when to resume, so you do not need a Zapier account. Use `FilesystemClient` for a single process, `MemoryClient` for tests, or write a `DurableClient` for Postgres, MySQL, or SQLite. The library does not include a scheduler.

## Related

> [card] [How Next Gen Zaps in code work](https://docs.zapier.com/sdk/define-durable.md)
>
> Learn how steps, waits, callbacks, and replays work.

> [card] [Deploy with client credentials](https://docs.zapier.com/sdk/deploy.md)
>
> Authenticate the SDK in production without a browser login.
