---
title: "EventWolf quickstart"
description: "Publish your product's events to EventWolf, see a retry deduplicated and a broken event rejected, read one request's history, and check what a subscription would match, through its HTTP API."
url: "https://agentpost.tools/docs/eventwolf/quickstart"
kind: quickstart
needs:
  - what: "The `api` helper, which sends a request and throws on an error"
    from: "https://agentpost.tools/docs/platform/quickstart.md"
  - what: "A `dev` secret key, `key`, for a project that adopted EventWolf"
    from: "https://agentpost.tools/docs/platform/guides/keys.md"
---

# EventWolf quickstart

At the end, your project holds the events of one support request, `r_9`, and you know which of them a subscription for resolved requests would match. Run the blocks in order as one script: later blocks use values from earlier ones. The [EventWolf API reference](/docs/eventwolf/reference.md) has every operation.

EventWolf answers for your project at `/v1/events` with your project’s secret key. If you created your project in the [Platform quickstart](/docs/platform/quickstart.md#3-create-a-project), use the Platform API key `token` from that quickstart to [adopt EventWolf](/docs/platform/guides/keys.md#2-adopt-a-service) by running ``await api('POST', `/v1/projects/${project.id}/services`, token, { service: 'eventwolf' })``. Keep using the same project `key` for the calls below.

## Before you start

-   The `api` helper, which sends a request and throws on an error, from [Platform quickstart](/docs/platform/quickstart.md).
-   A `dev` secret key, `key`, for a project that adopted EventWolf, from [Create a project and issue a key](/docs/platform/guides/keys.md).

This page's code continues the script of the pages above: run its blocks after theirs, in the same file. To run them as a script of their own, first copy each helper from the page that defines it, and set each other value, such as a key or an ID, to one you already have.

## 1\. Register an event type

Register `request.assigned` with a JSON Schema for its `data`. From now on, an event of this type whose data doesn’t match is rejected. `refPaths` makes the assignee’s ID a reference, so you can find the event by the principal:

```ts
const { eventType } = await api(
  'PUT',
  '/v1/events/event-types/request.assigned',
  key,
  {
    description: 'A support request was assigned to someone.',
    schema: {
      type: 'object',
      required: ['assignee'],
      properties: {
        assignee: {
          type: 'object',
          required: ['id'],
          properties: { id: { type: 'string' } },
        },
      },
    },
    refPaths: { 'assignee.id': { type: 'user' } },
  },
);
console.log(eventType.origin, eventType.schema.version); // registered 1
```

A project’s starting config accepts unregistered types and lists them as observed. [Event types](/docs/eventwolf/concepts/event-types.md) explains schemas and versions.

## 2\. Publish events

Publish what happened to request `r_9` as [CloudEvents](/docs/eventwolf/concepts/events.md): who created it, who it was assigned to, and how it was resolved. Each event’s `source` and `id` identify it. `subject` and `refs` say what it is about, and `actor` says who did it. One request takes up to 100 events as a batch:

```ts
const source = '/support/backend';
const events = [
  {
    type: 'request.created',
    actor: 'user:u_ben',
    data: { title: 'Refund for order 1042' },
  },
  {
    type: 'request.assigned',
    actor: 'user:u_ben',
    data: { assignee: { id: 'u_ana' } },
  },
  {
    type: 'request.resolved',
    actor: 'user:u_ana',
    data: { resolution: 'refunded' },
  },
].map((event) => ({
  specversion: '1.0',
  id: crypto.randomUUID(),
  source,
  subject: 'r_9',
  refs: 'request:r_9',
  ...event,
}));
const batch = { 'content-type': 'application/cloudevents-batch+json' };

const published = await api('POST', '/v1/events/events', key, events, batch);
console.log(published.results.map((result) => result.result));
// [ 'accepted', 'accepted', 'accepted' ]
```

Each accepted event gets a `sequence`, its place in your project’s order.

## 3\. Publish the same events again

A retry after a network error sends the same events again. EventWolf knows them by their `source` and `id`, so it answers `duplicate` without storing them again. Here the project key can publish the stored events, so each result includes the first sequence. [Duplicates](/docs/eventwolf/concepts/events.md#duplicates) explains when the sequence can be absent.

```ts
const again = await api('POST', '/v1/events/events', key, events, batch);
console.log(
  again.results.map((result) => result.result),
  again.results[1].sequence === published.results[1].sequence,
);
// [ 'duplicate', 'duplicate', 'duplicate' ] true
```

## 4\. See a rejected event

An event whose data breaks its type’s schema is rejected and recorded as an ingestion failure, so a broken deploy shows up right away. Here `assignee` is a string, not an object:

```ts
const broken = {
  specversion: '1.0',
  id: crypto.randomUUID(),
  source,
  type: 'request.assigned',
  subject: 'r_9',
  refs: 'request:r_9',
  data: { assignee: 'u_ana' },
};
const [rejected] = (
  await api('POST', '/v1/events/events', key, [broken], batch)
).results;
console.log(rejected.result, rejected.code); // rejected invalid_data

const { failures } = await api(
  'GET',
  '/v1/events/ingest-failures?type=request.assigned',
  key,
);
console.log(failures[0].claimed.id === broken.id, failures[0].issues);
// true [ 'data.assignee must be object' ]
```

Fix the producer and publish the event again with the same `id`. The [EventWolf errors](/docs/eventwolf/errors.md#invalid_data) explain what to do for each rejection.

## 5\. Read the request’s history

Read the events you published about `request:r_9`, oldest first:

```ts
const history = await api(
  'GET',
  '/v1/events/events?ref=request:r_9&order=asc',
  key,
);
console.log(history.events.map((record) => record.event.type));
// [ 'request.created', 'request.assigned', 'request.resolved' ]
```

The history holds each accepted event once. History queries and the live tail use the same [filter](/docs/eventwolf/concepts/filters.md) for types, sources, references, extensions, and values in `data`.

## 6\. Check what a subscription would match

A [subscription](/docs/eventwolf/concepts/subscriptions.md) sends the events that match its filter to your webhook, or to principals’ inboxes and phones. Before you create one, test its filter against events you have:

```ts
const filter = { types: ['request.resolved'] };
const [created, , resolved] = history.events;

const match = await api('POST', '/v1/events/subscriptions/test', key, {
  filter,
  sequence: resolved.sequence,
});
const miss = await api('POST', '/v1/events/subscriptions/test', key, {
  filter,
  sequence: created.sequence,
});
console.log(match.matched, miss.matched, miss.steps.at(-1).detail);
// true false type "request.created" is not one of ["request.resolved"]
```

Each step says which part of the filter matched or didn’t.

## Check it worked

Find the events about Ana. The type’s `refPaths` made the assignee a reference, so the assignment is among them:

```ts
const ana = await api('GET', '/v1/events/events?ref=user:u_ana', key);
console.log(ana.events.map((record) => record.event.type));
// [ 'request.resolved', 'request.assigned' ]
```

Ana is the resolved event’s `actor`, so it is about Ana too. Next, [Receive webhooks](/docs/eventwolf/guides/webhooks.md) creates the subscription and delivers resolved requests to your server; to notify principals instead, follow [Notify principals in their inbox](/docs/eventwolf/guides/notifications.md), and to bring in history from another system, [Import event history](/docs/eventwolf/guides/import-history.md).
