# Define event

`POST /v1/events`

Defines an event before it is sent, with the types its data has to carry. An event that is sent without being defined defines itself, with no types.

Needs the scope: `events:write`

## Body parameters

- `name` (string, required): A name for the event, such as `order.paid`: letters, digits, dots, dashes, colons and underscores.
- `schema` (Record<string, string>): The type of each value its data has to carry, by name: `string`, `number`, `boolean` or `date`. Without it the event takes any data.

## Returns

- `object` ("event"): Always `event`.
- `id` (string): The id of the event.
- `name` (string): The name of the event, such as `order.paid`.
- `schema` (Record<string, string> | null): The type of each value its data has to carry: `string`, `number`, `boolean` or `date`. `null` takes any data.
- `received` (integer): How many times it has been sent.
- `lastReceivedAt` (string | null): When it was last sent, or `null`.
- `createdAt` (string): When the event was first defined or sent.

## Example

cURL:

```bash
curl -X POST "$OPENSEND_API_URL/v1/events" \
  -H "Authorization: Bearer $OPENSEND_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "trial.started",
  "schema": {
    "plan": "string",
    "ends_at": "date"
  }
}'
```

TypeScript:

```ts
await opensend.events.create({
  name: 'trial.started',
  schema: {
    plan: 'string',
    ends_at: 'date',
  },
})
```

CLI:

```bash
opensend events create \
  --name trial.started \
  --schema '{"plan":"string","ends_at":"date"}'
```

MCP:

```json
{
  "name": "events_create",
  "arguments": {
    "name": "trial.started",
    "schema": {
      "plan": "string",
      "ends_at": "date"
    }
  }
}
```

Answer:

```json
{
  "object": "event",
  "id": "evt_trial.started",
  "name": "trial.started",
  "schema": {
    "plan": "string",
    "ends_at": "date"
  },
  "received": 0,
  "lastReceivedAt": null,
  "createdAt": "2026-11-27T09:30:00.000Z"
}
```
