# Listing-change webhooks

Source: https://help.ruuster.com/idx/guide-webhooks

> Set up listing-change webhooks, first on sample listings from your console and then on your live listings, verify each delivery's signature, handle single events and batches, and know how retries and test events work.

A listing-change webhook calls a URL on your server when a listing in your boards is created, changes
price, changes status or is removed. Your server re-renders the pages that show it, so search engines
and visitors see the change within minutes.

## Set it up

1. Deploy the webhook route first (the code is below), at a public `https` URL such as
   `https://www.example.com/api/ruuster-webhook`.
2. In your console, open **Keys and domains**, find **Sample webhooks** and press **Add a webhook**.
3. Enter the URL and pick the events you want. Most sites pick all four.
4. Copy the signing secret. It is shown once. Store it on your host as `RUUSTER_WEBHOOK_SECRET`.
5. Press **Send test**. Your route should answer 200. Check your function logs to see it arrive.

A sample webhook delivers the sample listings' changes through the day, signed the same way as a
live one, so you can build and test the whole route before you go live. You can hold up to two.

**For your live listings,** Ruuster adds the webhook for you in version 1. Once you are live, email
`helpme@ruuster.com` with the URL and the events you want. A live account can have up to five. Your
live webhook has its own signing secret, so put that one in `RUUSTER_WEBHOOK_SECRET` on your live
host.

The URL must use `https` and reach the public internet.

## The events

### Event kinds

| Kind | When it is sent |
|---|---|
| `listing.created` | A listing your key can show appeared (new to the market, or newly in your boards' scope). |
| `listing.price_changed` | The list price changed. `previous.price` holds the price before the change when the history has it. |
| `listing.status_changed` | The status changed, for example from active to pending. `previous.status` holds the earlier status when the history has it. |
| `listing.removed` | The listing can no longer be shown on your site. Answer its page with 410 Gone and drop it from your sitemap. |

### Headers

| Header | What it holds |
|---|---|
| `Ruuster-Event-Id` | The event id (the same as `id` in the body). A delivery can repeat: keep the ids you have handled and skip a repeat. |
| `Ruuster-Event-Kind` | The event kind, or `batch` for a body that holds several events. |
| `Ruuster-Delivery-Id` | This delivery attempt's id. Quote it when you contact support. |
| `Ruuster-Signature` | `t=<unix seconds>,v1=<hex>`. During a secret rotation there are two `v1` values; either may match. |

### Body

One event per delivery looks like this. A hidden-address listing has no street in its `slug`.

```json
{
  "id": "levt_aef04390d0666f2c405600aa",
  "kind": "listing.price_changed",
  "apiVersion": "v1",
  "occurredAt": "2026-11-03T14:20:00.000Z",
  "listing": {
    "id": "aaaaaaaa-0000-4000-8000-000000000001",
    "slug": "123-peachtree-st-ne-atlanta-ga-30308-aaaaaaaa-0000-4000-8000-000000000001",
    "mls": "FIXTURE",
    "mlsNumber": "FXSTD001",
    "status": "active",
    "price": 489000,
    "href": "https://idx.ruuster.com/v1/listings/aaaaaaaa-0000-4000-8000-000000000001"
  },
  "previous": {
    "price": 499000
  }
}
```

When several events are ready at once, one delivery carries them together:

```json
{
  "id": "bat_7d1e2f3a4b5c6d7e8f9a0b1c",
  "kind": "batch",
  "apiVersion": "v1",
  "count": 1,
  "events": [
    {
      "id": "levt_aef04390d0666f2c405600aa",
      "kind": "listing.price_changed",
      "apiVersion": "v1",
      "occurredAt": "2026-11-03T14:20:00.000Z",
      "listing": {
        "id": "aaaaaaaa-0000-4000-8000-000000000001",
        "slug": "123-peachtree-st-ne-atlanta-ga-30308-aaaaaaaa-0000-4000-8000-000000000001",
        "mls": "FIXTURE",
        "mlsNumber": "FXSTD001",
        "status": "active",
        "price": 489000,
        "href": "https://idx.ruuster.com/v1/listings/aaaaaaaa-0000-4000-8000-000000000001"
      },
      "previous": {
        "price": 499000
      }
    }
  ]
}
```

### Signature

Each delivery is signed. Read `Ruuster-Signature`, take `t` and every `v1`. Compute an HMAC-SHA256 with your signing secret over the text `<t>.<raw body>` and compare it, in constant time, with each `v1`. Accept the delivery when one matches and `t` is less than 300 seconds old. The SDK's `verifyWebhook` does all of this and gives you the events whether the body holds one event or a batch.

Each event carries the listing's `id`, `slug`, `mls`, `mlsNumber`, `status`, `price` and `href` (the
API URL of the listing), and `previous` with the earlier price or status where the listing's history
has it. Events are judged against your own boards and rules: a hidden address never appears in the
slug, and a sale on a board that doesn't show sold data arrives as `listing.removed`.

## The request

Every delivery is a `POST` with a JSON body and these headers:

| Header | What it holds |
|---|---|
| `Ruuster-Event-Id` | The event's id (for a batch, the batch's id) |
| `Ruuster-Event-Kind` | The event's kind, or `batch` |
| `Ruuster-Delivery-Id` | This delivery's id; a retry of the same delivery keeps it |
| `Ruuster-Signature` | `t=<unix seconds>,v1=<signature>` |

The body is one event, or, when many listings changed at once, a batch:
`{ "id", "kind": "batch", "apiVersion": "v1", "count", "events": [ … ] }`.

## Verify the signature

The signature is HMAC-SHA256, keyed with your signing secret, over the timestamp, a period and the raw
body (`<t>.<body>`), in hex. While you rotate the secret, the header carries one `v1=` for each secret;
accept the delivery when any of them matches. Reject a timestamp more than five minutes from your
clock.

`verifyWebhook` from `@ruuster/idx` does all of this with a constant-time compare and returns the
events as a list, whether the body held one event or a batch:

<p class="code-title"><code>app/api/ruuster-webhook/route.ts</code></p>

```ts
// POST /api/ruuster-webhook: Ruuster calls it when a listing in your boards is created, changes price
// or status, or is removed. Add this URL under Webhooks in Settings > Ruuster Listings API, and
// put the signing secret in RUUSTER_WEBHOOK_SECRET.
import { revalidatePath } from "next/cache";
import { handleRuusterWebhook } from "@/lib/revalidate";

export const dynamic = "force-dynamic";

export function POST(req: Request) {
  return handleRuusterWebhook(req, { secret: process.env.RUUSTER_WEBHOOK_SECRET, revalidatePath });
}
```

`handleRuusterWebhook` in `lib/revalidate.ts` calls `verifyWebhook` and re-renders the pages each
event touches:

<p class="code-title"><code>lib/revalidate.ts</code></p>

```ts
// The listing-change webhook: verify the signature, re-render the pages the change touches, answer fast.
// Deliveries arrive at least once and in any order, so the handler only re-renders: doing it twice is harmless.
import { verifyWebhook, type ListingEvent } from "@ruuster/idx";

/** The list pages any listing change can touch (re-rendered once per delivery). */
export const LIST_PAGES: readonly { path: string; type?: "page" | "layout" }[] = [
  { path: "/" },
  { path: "/neighborhoods/[area]", type: "page" },
  { path: "/neighborhoods/[area]/sold", type: "page" },
  { path: "/our-listings" },
  { path: "/open-houses" },
  { path: "/price-reduced" },
  { path: "/new-construction" },
  { path: "/agents/[agent]", type: "page" },
];

/** The listing page paths one event touches: its href's path, and /homes/<slug>. */
export function listingPathsOf(event: ListingEvent): string[] {
  const out = new Set<string>();
  const href = event.listing.href;
  if (href) {
    try {
      out.add(new URL(href, "http://localhost").pathname);
    } catch {
      // An href that is not a URL is skipped; the slug path below still covers the page.
    }
  }
  if (event.listing.slug) out.add(`/homes/${event.listing.slug}`);
  return [...out];
}

export type WebhookDeps = {
  /** RUUSTER_WEBHOOK_SECRET; two comma-separated values while you rotate it. */
  secret: string | undefined;
  revalidatePath: (path: string, type?: "page" | "layout") => void;
  now?: Date;
};

export async function handleRuusterWebhook(req: Request, deps: WebhookDeps): Promise<Response> {
  if (!deps.secret) return Response.json({ ok: false, error: "RUUSTER_WEBHOOK_SECRET is not set on this server." }, { status: 500 });
  const body = await req.text();
  const secrets = deps.secret.split(",").map((s) => s.trim()).filter(Boolean);
  const v = await verifyWebhook({ body, headers: req.headers, secret: secrets, now: deps.now });
  if (!v.ok) return Response.json({ ok: false, error: v.reason }, { status: 401 });
  const paths = new Set<string>();
  for (const e of v.events) for (const p of listingPathsOf(e)) paths.add(p);
  for (const p of paths) deps.revalidatePath(p);
  for (const l of LIST_PAGES) deps.revalidatePath(l.path, l.type);
  return Response.json({ ok: true, events: v.events.length, deliveryId: v.deliveryId });
}
```

Read the body as raw text before you parse it. A framework that parses JSON first changes the bytes,
and the signature no longer matches.

## Answer fast, then work

- Answer with any 2xx within a few seconds. Do slow work, such as rebuilding a sitemap, after you
  answer, or in a queue.
- **At least once:** the same event can arrive more than once. Each event's `id` is the same on every
  delivery, so keep the ids you have handled for a day and skip repeats, or make your handler safe to
  run twice (re-rendering a page is).
- **No fixed order:** events can arrive out of order. Re-read the listing, or re-render its page,
  rather than applying `previous` and the new values as a diff.

## Retries and failures

A delivery that doesn't get a 2xx is retried with growing waits, from one minute up to twelve hours
between attempts. After 20 failed runs in a row the webhook is turned off. A sample webhook shows
that, with the last error, in your console. Fix the route, then email `helpme@ruuster.com` to have a
live webhook turned back on. While a webhook is off, poll `/v1/changes`
([Keeping pages fresh](https://help.ruuster.com/idx/guide-freshness)) to catch up.

## Rotating the secret

To rotate a live webhook's secret, email `helpme@ruuster.com`. For a while every delivery is signed
with both the new and the old secret, so you can deploy the new one without missing a delivery.
Pass both secrets to `verifyWebhook` as a list during the switch. For a sample webhook, delete it
and add it again to get a new secret.

[Webhook events](https://help.ruuster.com/idx/reference-webhook-events) is the reference.
