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

# Wendung.flush(): Send queued events now

> Send one batch of queued events via fetch. Returns a Promise that resolves when the request settles. Server errors re-queue; client errors are dropped.

Call `Wendung.flush()` when you want a send attempt to settle before a specific action, such as navigating to an external URL or asserting in a test. Each call sends at most one batch (up to the effective batch size); events beyond that stay queued for later flushes. Normally you never need this: the SDK flushes automatically on a timer, on batch fill, and on page hide or unload.

Throws if called before [`init()`](/api-reference/init).

```typescript theme={null}
Wendung.flush(): Promise<void>
```

## Parameters

None.

## Returns

<ResponseField name="Promise<void>" type="Promise<void>">
  Resolves when the HTTP request has settled; it never rejects. Resolves immediately without a network request if the queue is empty or `fetch` is unavailable.
</ResponseField>

## Error handling

* **4xx responses**: the batch is dropped permanently and a `[Wendung - Warning]` is logged. These typically indicate a malformed payload or invalid API key.
* **5xx responses and network errors**: the batch is re-queued at the front with the same `batchId` and retried on the next flush. There is no backoff and no retry cap.

## Examples

### Flush before external navigation

```typescript theme={null}
async function handleExternalLink(url: string) {
  await Wendung.flush()
  window.location.href = url
}
```

### Flush in a test

```typescript theme={null}
it('tracks checkout_completed', async () => {
  Wendung.step('checkout_completed', { plan: 'pro' })
  await Wendung.flush()

  expect(mockFetch).toHaveBeenCalledWith(
    expect.stringContaining('/v1/events'),
    expect.objectContaining({ method: 'POST' }),
  )
})
```

<Note>
  `flush()` sends one batch per call. To drain the entire queue in one call, use [`sendBeacon()`](/api-reference/send-beacon), which is also the better choice in unload handlers because it sends with `keepalive`.
</Note>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.