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

# occtoo events

> Watch live events, read past events, and manage webhooks, queues and durable consumers

Use `occtoo events` to watch what happens in your organization as it happens, read the events Occtoo has kept, and manage event destinations. See the [Events API](https://docs.occtoo.com/api-reference/events/overview.md) for the event types and their payloads.

## Filters

`subscribe`, `list` and `metadata` take `--filter`, and event destinations have a filter too. A filter uses `eq`, `and`, `or`, parentheses and double-quoted strings:

```text theme={null}
type eq "source.updated"
(type eq "source.updated" and sourceId eq "products") or type eq "segment.updated"
```

Run `occtoo events types` to see the event types and what a filter can compare for each.

## Watch live events

```bash theme={null}
occtoo events subscribe
occtoo events subscribe --filter 'type eq "source.updated" and sourceId eq "products"'
occtoo events subscribe --output json | jq .data
```

Prints events as they happen, until you press Ctrl-C. The stream reconnects by itself and continues after the last event it showed.

| Flag | Description |
| - | - |
| `--filter <FILTER>` | Only events that match this filter |
| `--after <AFTER>` | Start after this position instead of now: a cursor, or the sequence of an event |
| `--output <text\|json>` | One readable line per event (default), or one JSON document per line |

## Read past events

```bash theme={null}
occtoo events list --limit 20
occtoo events list --filter 'type eq "source.updated"' --output json | jq -r .subject
occtoo events list --after 00000000000000001234
```

Reads the events Occtoo has kept, oldest first. To continue where a run stopped, pass the `sequence` of its last event to `--after`. `occtoo events subscribe --after` continues the same way and then keeps listening.

| Flag | Description |
| - | - |
| `--filter <FILTER>` | Only events that match this filter |
| `--after <AFTER>` | Start after this position instead of at the oldest event |
| `--limit <LIMIT>` | Maximum number of events to return. Default `100` |
| `--output <text\|json>` | One readable line per event (default), or one JSON document per line |

## Find out what there is

```bash theme={null}
occtoo events metadata
occtoo events types
occtoo events schema source.updated
```

* `metadata` shows how many events Occtoo has kept and where they start and end. It takes `--filter`.
* `types` lists the event types and what a filter can compare for each.
* `schema <TYPE>` prints the JSON Schema of the payload of an event type. `--version <major.minor>` prints an earlier version.

## Event destinations

An event destination receives the events that match its filter. It is one of four types:

* `Webhook`: Occtoo calls an HTTPS address.
* `AzureStorageQueue`: Occtoo writes to an Azure Storage queue.
* `AzureServiceBus`: Occtoo writes to an Azure Service Bus queue or topic.
* `DurableConsumer`: your own workers pull events in batches.

You can name a destination by its id or its name.

```bash theme={null}
occtoo events destinations list
occtoo events destinations show "Orders hook"
occtoo events destinations create
occtoo events destinations edit "Orders hook"
occtoo events destinations delete "Orders hook" --yes
```

| Command | What it does |
| - | - |
| `list` | Lists event destinations. `--limit` defaults to `100` |
| `show <DESTINATION>` | Shows an event destination |
| `create` | Creates an event destination from prompts or JSON |
| `edit <DESTINATION>` | Changes the name, filter or settings. In a terminal, it prompts for the name and filter |
| `delete <DESTINATION>` | Deletes an event destination and cancels its pending deliveries |
| `verify <DESTINATION>` | Asks a webhook's address whether it accepts events from Occtoo, and activates it |
| `pause <DESTINATION>` | Stops delivery. Pending deliveries are cancelled |
| `resume <DESTINATION>` | Starts delivery again. A webhook or queue skips what happened while it was paused. A durable consumer continues where it stopped |
| `deliveries <DESTINATION>` | Lists the recent deliveries of a webhook or queue, newest first |
| `pull <DESTINATION>` | Takes the next batch of events of a durable consumer |
| `ack <DESTINATION> <LEASE> <GENERATION>` | Tells a durable consumer that a batch is handled |

### Create a destination

`type` can't change later. `configuration` holds the settings of the type, and a durable consumer takes none:

```json theme={null}
{"name": "Orders hook", "type": "Webhook", "filter": "type eq \"source.updated\"", "configuration": {"endpoint": "https://example.com/hooks/occtoo"}}
{"name": "Queue", "type": "AzureStorageQueue", "filter": "...", "configuration": {"connectionString": "...", "queueName": "occtoo-events"}}
{"name": "Bus", "type": "AzureServiceBus", "filter": "...", "configuration": {"connectionString": "...", "entityName": "occtoo-events"}}
{"name": "Worker", "type": "DurableConsumer", "filter": "..."}
```

* Every branch of the filter has to name a type.
* Only events that happen after the destination is active are delivered.
* A webhook delivers nothing until you run `verify`. Its signing secret is printed once, when you create it.
* A connection string is a secret. In a terminal it is asked for without echo. Otherwise, pipe the JSON in rather than keeping it in a file. It is never a flag.

For `edit`, every field is optional. A new webhook address has to be verified again.

### Deliveries

```bash theme={null}
occtoo events destinations deliveries "Orders hook" --failed
```

`--failed` shows only deliveries that failed, with the error of their last attempt. `--limit` defaults to `50`. Occtoo keeps delivered events for an hour and failed ones for seven days. A durable consumer has no deliveries.

### Durable consumers

A durable consumer hands out events in batches that you have to acknowledge. See [Durable consumers](https://docs.occtoo.com/api-reference/events/durable-consumers.md) for how they work.

```bash theme={null}
occtoo events destinations pull Worker --ack
```

Prints the next batch and acknowledges it. To handle a batch before you acknowledge it, take it as JSON and acknowledge it afterwards:

```bash theme={null}
batch=$(occtoo events destinations pull Worker --output json)
occtoo events destinations ack Worker $(jq -r '.leaseId, .generation' <<< "$batch")
```

With `--output json`, the batch is one document: `{"leaseId", "generation", "attempt", "events"}`. `pull` prints nothing when there are no new events.

| Flag (`pull`) | Description |
| - | - |
| `--limit <LIMIT>` | Maximum number of events to take. Default `20` |
| `--visibility <SECONDS>` | Seconds the batch stays yours before it is handed out again. Default `60` |
| `--worker <WORKER>` | Name of this worker, when several take events from the destination at once |
| `--ack` | Acknowledge the batch as soon as it is printed |
| `--output <text\|json>` | One readable line per event (default), or the batch as one JSON document |

Acknowledge a batch within the visibility time, or its events are handed out again. If you can't handle a batch, run `ack` with `--failed` to have it handed out again right away.


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