# Live healthcare job and license stream (/recipes/live-job-stream)

Open one stream and keep it open. Each time a posting appears, closes, comes back, or changes
pay, you get one event. Each event carries the page it came from, so you can hash it and keep
your own receipt.

```sh
curl -N https://api.bowmark.ai/v1/streams/healthcare-ga-tx/events \
  -H "Authorization: Bearer $BOWMARK_API_KEY" \
  -H "Accept: text/event-stream"
```

## What it covers

| Source                                                | What it watches                              | How often    |
| ----------------------------------------------------- | -------------------------------------------- | ------------ |
| Houston Methodist, Memorial Hermann (TX)              | Nurse openings on their Workday boards       | Every 20 min |
| Northeast Georgia Health System, Wellstar, Emory (GA) | Nurse openings on their careers boards       | Every 20 min |
| Harborview (GA), Avir (TX) nursing homes              | Nurse openings, with hourly pay where posted | Every 30 min |
| Texas Board of Nursing                                | The licensure processing-time notice         | Hourly       |
| TX and GA nurse licenses                              | Status of watched licenses                   | Hourly       |

A board that asks us to slow down is polled less often until it is ready.

## Event types

| Type                            | Sent when                                                                               |
| ------------------------------- | --------------------------------------------------------------------------------------- |
| `job.posted`                    | A new opening appears                                                                   |
| `job.closed`                    | An opening is gone from the board on two polls in a row                                 |
| `job.reposted`                  | A closed opening comes back, under the same or a new req id, or the board re-dates it   |
| `job.pay_changed`               | The posted pay changes. `data.previous` has the old pay                                 |
| `job.updated`                   | Title, location, department, job type or shift changes. `data.changed` names the fields |
| `board.processing_time_changed` | The Texas Board of Nursing changes its processing-time notice                           |
| `license.status_changed`        | A watched license's status changes                                                      |
| `license.updated`               | A watched license's dates change                                                        |
| `lookup.completed`              | An async license lookup you submitted has its answer. Only you see it                   |

## One event

```json
{
  "id": "evt_1a2436d93700a91c7719833",
  "type": "job.posted",
  "stream": "healthcare-ga-tx",
  "source": "wellstar",
  "subject": "Wellstar Health System",
  "req_id": "JR-25990",
  "occurred_at_utc": "2026-11-25T00:00:00.000Z",
  "detected_at_utc": "2026-12-04T23:39:42.101Z",
  "data": {
    "job": {
      "req_id": "JR-25990",
      "title": "Registered Nurse",
      "employer": "Wellstar Health System",
      "location": "Marietta, Georgia",
      "city": "Marietta",
      "state": "GA",
      "department": "Nursing",
      "employment_type": "Full time",
      "shift": [],
      "posted_at": "2026-11-25",
      "posted_at_source": "posting",
      "pay_min": null,
      "pay_max": null,
      "pay_period": null,
      "pay_currency": null,
      "apply_url": "https://careers.wellstar.org/us/en/job/JR-25990",
      "requires_account_to_apply": null,
      "ats": "phenom"
    },
    "poll": { "polled_at_utc": "2026-12-04T23:39:30.482Z", "jobs_read": 517 }
  },
  "evidence": {
    "source_url": "https://careers.wellstar.org/us/en/job/JR-25990",
    "fetched_at_utc": "2026-12-04T23:39:40.020Z",
    "http_status": 200,
    "raw_body_sha256": "d9b8cbb47090…",
    "raw_body_url": "https://api.bowmark.ai/v1/streams/evidence/d9b8cbb47090…",
    "content_type": "text/html; charset=utf-8",
    "bytes": 106580
  }
}
```

`posted_at_source` is `posting` when the posting states its date, and `board` when the board
only says "Posted 3 days ago". A `job.closed` event's evidence is the posting's page fetched at
that moment, so its `http_status` is often `404` or `410`.

## Check the evidence

`raw_body_url` returns the exact bytes we received, with your key. Their SHA-256 is
`raw_body_sha256`:

```sh
curl -s "$RAW_BODY_URL" -H "Authorization: Bearer $BOWMARK_API_KEY" | shasum -a 256
```

## Resume after a disconnect

Every event has an `id`. Reconnect with the last one you saw and you get everything after it,
in order, with nothing skipped:

```sh
curl -N https://api.bowmark.ai/v1/streams/healthcare-ga-tx/events \
  -H "Authorization: Bearer $BOWMARK_API_KEY" \
  -H "Accept: text/event-stream" \
  -H "Last-Event-ID: evt_1a2436d93700a91c7719833"
```

| Query                          | What it does                           |
| ------------------------------ | -------------------------------------- |
| `?after=<id>`                  | Same as `Last-Event-ID`                |
| `?from=start`                  | Replay the stream from its first event |
| `?types=job.posted,job.closed` | Only these event types                 |

An id the stream never sent answers `409`, so you never miss events silently. Without
`Accept: text/event-stream` the same URL returns a JSON page with `next_after`.

## A consumer in Node

Subscribes, prints each event, and picks up where it left off after any disconnect. Node 18 or
newer, no packages.

```js
// BOWMARK_API_KEY=... node stream.mjs
const url = "https://api.bowmark.ai/v1/streams/healthcare-ga-tx/events";
let last = process.env.LAST_EVENT_ID || "";
for (;;) {
  try {
    const headers = { authorization: `Bearer ${process.env.BOWMARK_API_KEY}`, accept: "text/event-stream" };
    if (last) headers["last-event-id"] = last;
    const res = await fetch(url, { headers });
    if (!res.ok) throw new Error(`HTTP ${res.status}`);
    let buf = "";
    for await (const chunk of res.body.pipeThrough(new TextDecoderStream())) {
      buf += chunk;
      for (let i; (i = buf.indexOf("\n\n")) >= 0; buf = buf.slice(i + 2)) {
        const data = /^data: (.*)$/m.exec(buf.slice(0, i))?.[1];
        if (!data) continue;
        const e = JSON.parse(data);
        console.log(e.detected_at_utc, e.type, e.subject, e.req_id, e.data.job?.title ?? "");
        last = e.id;
      }
    }
  } catch (err) { console.error("disconnected:", err.message); }
  await new Promise((r) => setTimeout(r, 3000));
}
```

## Slow license lookups, answered as events

A license search on a state board can take 20 to 40 seconds. Submit it and get an id back at
once. The answer arrives on your stream as a `lookup.completed` event whose `req_id` is that id.

```sh
curl -sS -X POST https://api.bowmark.ai/v1/streams/healthcare-ga-tx/lookups \
  -H "Authorization: Bearer $BOWMARK_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"kind":"tx_nurse_license","licenseNumber":"674156","licenseType":"RN"}'
```

| `kind`             | Search by                                                                                     |
| ------------------ | --------------------------------------------------------------------------------------------- |
| `tx_nurse_license` | `licenseNumber`, or `lastName` and `firstName`, plus optional `licenseType` (`RN`, `LVN/LPN`) |
| `ga_nurse_license` | `licenseNumber`, or `lastName` and optional `firstName`                                       |

`GET /v1/streams/healthcare-ga-tx/lookups/<id>` returns its status and, once done, the event id.

## Push to a webhook instead

Prefer push? Register an https URL. Events are POSTed to it in order, in batches, retried until
your server answers 2xx.

```sh
curl -sS -X POST https://api.bowmark.ai/v1/streams/healthcare-ga-tx/webhooks \
  -H "Authorization: Bearer $BOWMARK_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"url":"https://example.com/bowmark-events"}'
```

The answer includes a `secret`, shown once. Each POST body is `{ "stream", "events": [...] }`
and carries `Bowmark-Signature: t=<unix seconds>,v1=<hex>`. Check it:

```js
import { createHmac, timingSafeEqual } from "node:crypto";
const [t, v1] = header.split(",").map((p) => p.split("=")[1]);
const want = createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex");
const ok = timingSafeEqual(Buffer.from(want), Buffer.from(v1));
```

Delivery is at least once: dedupe on event `id`. `GET /v1/streams/webhooks` lists yours with
their last delivery, and `DELETE /v1/streams/webhooks/<id>` removes one.

## Health

`GET /v1/streams` lists each stream's sources with when each was last read and whether it is
healthy.
