> ## 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.

# WendungServer: Send funnel steps from your server

> Create a server client with a secret key and record funnel steps that happen only on your server, such as payments confirmed by a webhook.

`WendungServer` sends funnel steps from server code with a [secret key](https://docs.wendung.app/guides/server-events.md#create-a-secret-key). Each call sends one step and waits for ingest to accept it. There is no queue or flush timer, so it works in serverless functions that stop after the response.

```typescript theme={null}
import { WendungServer } from '@wendung/sdk/server'

new WendungServer(config: ServerConfig)
wendung.step(name: string, step: ServerStep): Promise<ServerStepResult>
```

It uses only `fetch`, so it runs on Node.js 18 or newer, Cloudflare Workers, Vercel Edge Functions, and Deno.

## Constructor

**secretKey** `string` *required*

The project's secret key. It must start with `sk_`; the constructor throws otherwise. Read it from the server environment, never from frontend code.

**endpoint** `string` (default: [https://ingest.wendung.app/v1/events](https://ingest.wendung.app/v1/events))

The ingest URL.

**debug** `boolean` (default: false)

Logs accepted steps with `console.log`. Failures always log with `console.warn`.

## step()

**name** `string` *required*

The step name, 1 to 100 characters. Names that start with `$` are reserved.

**step.id** `string` *required*

A unique ID for this step, up to 100 characters. Use the source event's own ID, such as a Stripe event ID, so a retried webhook is stored once.

**step.userId** `string` *required*

The user the step belongs to, up to 255 characters. Use the same ID you pass to [`identify()`](https://docs.wendung.app/api-reference/identify) in the browser.

**step.timestamp** `Date | string` *required*

When the step happened, as a `Date` or an ISO 8601 string. Ingest accepts steps up to 7 days old and at most 5 minutes in the future.

**step.properties** `Record\<string, unknown\>`

Optional metadata for this step, up to 20 top-level keys.

### Returns

`Promise<ServerStepResult>`. It never rejects.

| Result | Meaning |
| - | - |
| `{ ok: true, status }` | Ingest accepted the step. `status` is `202`. |
| `{ ok: false, status, error }` | Ingest rejected the step, or the request failed. `status` is `null` for network failures and invalid timestamps. |

`step()` retries `429` responses, `5xx` responses, and network failures up to three attempts, waiting 0.5 and then 1 second between them. Other `4xx` responses are returned without a retry. See [Errors](https://docs.wendung.app/guides/server-events.md#errors) for the rejection reasons.

## Example

```typescript theme={null}
import { WendungServer } from '@wendung/sdk/server'

const wendung = new WendungServer({
  secretKey: process.env.WENDUNG_SECRET_KEY!,
})

const result = await wendung.step('payment_succeeded', {
  id: event.id,
  userId: appUserId,
  timestamp: new Date(event.created * 1000),
  properties: { plan: 'pro' },
})

if (!result.ok) {
  console.error('Wendung did not record the payment', result.error)
}
```


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