---
title: Node.js | Avara
description: Handle AutoScribe webhooks in Node.js.
---

You almost never need all six webhooks. Read [What webhooks should I configure](/integration/autoscribe/what-webhooks-should-i-configure/index.md) first — it maps each integration profile to the endpoints you should set, based on the products you or your customer use and the end behavior you want. Leave unused endpoints blank.

This page is the Node.js implementation guide: verify signatures, then handle only the events you enabled.

## Webhook security

All webhook requests from Avara are signed using HMAC-SHA256 with Standard Webhooks headers (`webhook-id`, `webhook-timestamp`, `webhook-signature`). Copy the webhook secret from [API Config](/integration/autoscribe/api-config/index.md) (**View Webhook Secret**) and set it as the `AVARA_WEBHOOK_KEY` environment variable. The SDK’s `unwrap()` method reads that variable, verifies the signature, and returns a typed event. Every Avara→partner POST expects **HTTP 200** with a JSON body matching that event’s response schema. Synchronous hooks should respond within about **30 seconds**.

You can use `unsafeUnwrap()` instead of `unwrap()` to skip signature verification, but this is not recommended for production as it bypasses security checks.

```
import Avara from "avara";
import http from "node:http";


const client = new Avara(); // reads AVARA_WEBHOOK_KEY from env


http.createServer(async (req, res) => {
  const chunks = [];
  for await (const chunk of req) {
    chunks.push(chunk);
  }
  const body = Buffer.concat(chunks);
  const event = client.webhooks.unwrap(body, req.headers);


  if (event.type === "study.access_requested") {
    // Handle study access request
    const { studyId, studyInstanceUid } = event.data;
    // ...
  }


  if (event.type === "secondary_capture.access_requested") {
    // Handle secondary capture upload request
    const { studyId, studyInstanceUid } = event.data;
    // ...
  }


  if (event.type === "report.delivered") {
    // Handle report delivery
    const { reportId, studyId, presignedUrl, isCritical } = event.data;
    // ...
  }


  if (event.type === "modality_worklist.requested") {
    // Handle modality worklist request
    const { clinicId, callingAe, dateStart, dateEnd } = event.data;
    // ...
  }


  if (event.type === "patient_study.enrichment_requested") {
    // Handle patient/study enrichment
    const { clinicId, studyInstanceUid } = event.data;
    // ...
  }


  if (event.type === "clinical_context.enrichment_requested") {
    // Handle clinical context enrichment
    const { clinicId, studyInstanceUid, studyId } = event.data;
    // ...
  }
});
```

## Study Image Access

The `study.access_requested` webhook is sent when Avara needs presigned URLs for DICOM images (and optional non-DICOM media). This is a **synchronous (hard) webhook** — you must respond within about 30 seconds. This webhook is sent before a study can be viewed in the Avara interface.

When Avara needs to access study images, it sends a POST request to your webhook endpoint. Your endpoint must respond with presigned GET URLs. The SDK’s `unwrap()` method returns a typed `StudyAccessRequestedWebhookEvent` that you can use directly.

Return `authorized: false` with an `error` when the caller must not access the study. Returning `authorized: true` with an empty `urls` array (and omitted or empty `mediaUrls`) is treated as no data available, not as a denial.

```
import Avara from "avara";
import http from "node:http";


const client = new Avara();


http.createServer(async (req, res) => {
  const chunks = [];
  for await (const chunk of req) {
    chunks.push(chunk);
  }
  const body = Buffer.concat(chunks);
  const event = client.webhooks.unwrap(body, req.headers);


  if (event.type === "study.access_requested") {
    const { studyId, studyInstanceUid } = event.data;


    // This is your internal business logic
    const presignedUrls = await generatePresignedUrlsForStudy(studyInstanceUid);


    if (presignedUrls.length === 0) {
      res.writeHead(200, { "Content-Type": "application/json" });
      res.end(JSON.stringify({
        authorized: false,
        error: "Study not found in PACS",
      }));
      return;
    }


    res.writeHead(200, { "Content-Type": "application/json" });
    res.end(JSON.stringify({
      authorized: true,
      urls: presignedUrls,
    }));
  }
});


// This is your internal business logic
async function generatePresignedUrlsForStudy(studyInstanceUid) {
  // Query your PACS/RIS system for the study
  // Generate presigned URLs for each DICOM image
  // Return a flat list of all image URLs
  return [
    "https://storage.example.com/dicom/image1.dcm?token=abc123",
    "https://storage.example.com/dicom/image2.dcm?token=def456",
  ];
}
```

**Response Format**

```
/**
 * @typedef {Object} StudyAccessRequestedWebhookResponse
 * @property {boolean} authorized
 * @property {string[]} urls
 * @property {Array<{url: string, mimeType: string, fileName?: string}>} [mediaUrls]
 * @property {string} [error]
 */
```

## Secondary Capture Upload

The `secondary_capture.access_requested` webhook is sent when a viewer user creates a secondary capture. This is a **synchronous (hard) webhook** — you must return presigned PUT URLs in-request, within about 30 seconds.

Avara asks for upload URLs before writing the generated DICOM to your storage. The SDK’s `unwrap()` method returns a typed `SecondaryCaptureAccessRequestedWebhookEvent`. Respond `authorized: false` with an `error` if the study cannot be written. `uploadUrls` must be PUT-capable; the client uploads with `Content-Type: application/dicom` and writes the same object to every URL. Series and SOP UIDs are provided when available so you can pre-compute object keys. If you send `contentCreatorName`, Avara ignores it and derives the creator name server-side.

```
import Avara from "avara";
import http from "node:http";


const client = new Avara();


http.createServer(async (req, res) => {
  const chunks = [];
  for await (const chunk of req) {
    chunks.push(chunk);
  }
  const body = Buffer.concat(chunks);
  const event = client.webhooks.unwrap(body, req.headers);


  if (event.type === "secondary_capture.access_requested") {
    const { studyId, studyInstanceUid, seriesInstanceUid, sopInstanceUid } =
      event.data;


    // This is your internal business logic
    const uploadUrls = await generateSecondaryCaptureUploadUrls({
      studyInstanceUid,
      seriesInstanceUid,
      sopInstanceUid,
    });


    if (uploadUrls.length === 0) {
      res.writeHead(200, { "Content-Type": "application/json" });
      res.end(JSON.stringify({
        authorized: false,
        error: "Study cannot be written",
      }));
      return;
    }


    res.writeHead(200, { "Content-Type": "application/json" });
    res.end(JSON.stringify({
      authorized: true,
      uploadUrls,
    }));
  }
});


// This is your internal business logic
async function generateSecondaryCaptureUploadUrls(params) {
  // Generate presigned PUT URLs for the secondary capture DICOM
  return [
    "https://storage.example.com/dicom/sc/image.dcm?token=abc123",
  ];
}
```

**Response Format**

```
/**
 * @typedef {Object} SecondaryCaptureAccessRequestedWebhookResponse
 * @property {boolean} authorized
 * @property {string[]} uploadUrls
 * @property {string} [contentCreatorName]
 * @property {string} [error]
 */
```

## Report Delivery

The `report.delivered` webhook is sent when a report is completed and delivered. This is an **asynchronous notification** — respond with a simple success acknowledgment. The webhook includes plain text content, a presigned URL for PDF download, and `isCritical` (whether the report was marked critical at sign-off).

When a report is completed, Avara sends a POST request to your webhook endpoint. Your endpoint should process the report and respond with a success acknowledgment. The SDK’s `unwrap()` method returns a typed `ReportDeliveredWebhookEvent` that you can use directly.

```
import Avara from "avara";
import http from "node:http";


const client = new Avara();


http.createServer(async (req, res) => {
  const chunks = [];
  for await (const chunk of req) {
    chunks.push(chunk);
  }
  const body = Buffer.concat(chunks);
  const event = client.webhooks.unwrap(body, req.headers);


  if (event.type === "report.delivered") {
    const { reportId, studyId, plainText, presignedUrl, isCritical } = event.data;


    // This is your internal business logic
    await processCompletedReport({
      reportId,
      studyId,
      plainText,
      presignedUrl,
      isCritical,
    });


    res.writeHead(200, { "Content-Type": "application/json" });
    res.end(JSON.stringify({ success: true }));
  }
});


// This is your internal business logic
async function processCompletedReport(data) {
  // Download the PDF from the presigned URL
  // Store the report in your system
  // Update your PACS/RIS with the completed report
  // Notify relevant users or systems
}
```

**Response Format**

```
/**
 * @typedef {Object} ReportDeliveredWebhookResponse
 * @property {boolean} success
 */
```

## Modality Worklist

The `modality_worklist.requested` webhook is sent when an on-prem modality (via an Avara PACS box) issues a C-FIND MWL. This is a **synchronous (hard) webhook** — the C-FIND path waits on your response, which should return within about 30 seconds.

Avara forwards the query window to your endpoint. Only one active API key per organization may have the Modality Worklist Webhook Endpoint set. The SDK’s `unwrap()` method returns a typed `ModalityWorklistRequestedWebhookEvent`. Return `authorized: false` with an `error` to surface a worklist failure to the modality. `items` is required and may be empty when there are no scheduled exams.

Item field names are PascalCase DICOM-style (not camelCase). `StudyInstanceUID` is required from the partner RIS today — do not omit it. `PatientName`, `PatientID`, and `Modality` must be non-empty. `ScheduledProcedureStepSequence` must contain at least one step.

```
import Avara from "avara";
import http from "node:http";


const client = new Avara();


http.createServer(async (req, res) => {
  const chunks = [];
  for await (const chunk of req) {
    chunks.push(chunk);
  }
  const body = Buffer.concat(chunks);
  const event = client.webhooks.unwrap(body, req.headers);


  if (event.type === "modality_worklist.requested") {
    const { clinicId, callingAe, sourceIp, dateStart, dateEnd, modality } =
      event.data;


    // This is your internal business logic
    const items = await queryModalityWorklist({
      clinicId,
      callingAe,
      sourceIp,
      dateStart,
      dateEnd,
      modality,
    });


    res.writeHead(200, { "Content-Type": "application/json" });
    res.end(JSON.stringify({
      authorized: true,
      items,
    }));
  }
});


// This is your internal business logic
async function queryModalityWorklist(params) {
  return [
    {
      PatientName: "DOE^JANE",
      PatientID: "MRN12345",
      PatientBirthDate: "19800115",
      PatientSex: "F",
      PatientSize: "1.65",
      PatientWeight: "62",
      Modality: "CT",
      AccessionNumber: "ACC-1001",
      StudyInstanceUID: "1.2.840.113619.2.55.3.604688119.868.1234567890.123",
      RequestedProcedureDescription: "CT CHEST WO CONTRAST",
      StudyDescription: "CT CHEST WO CONTRAST",
      ProtocolName: "CHEST_WO",
      ScheduledProcedureStepSequence: [
        {
          ScheduledProcedureStepStartDate: "20260813",
          ScheduledProcedureStepStartTime: "090000",
          ScheduledProcedureStepID: "SPSID-1",
          Modality: "CT",
          ScheduledProcedureStepDescription: "CT CHEST WO CONTRAST",
        },
      ],
    },
  ];
}
```

**Response Format**

```
/**
 * @typedef {Object} ModalityWorklistRequestedWebhookResponse
 * @property {boolean} authorized
 * @property {ModalityWorklistItem[]} items
 * @property {string} [error]
 *
 * @typedef {Object} ModalityWorklistItem
 * @property {string} PatientName
 * @property {string} PatientID
 * @property {string} PatientBirthDate
 * @property {string} PatientSex
 * @property {string} PatientSize
 * @property {string} PatientWeight
 * @property {string} Modality
 * @property {string} AccessionNumber
 * @property {string} StudyInstanceUID
 * @property {string} RequestedProcedureDescription
 * @property {string} StudyDescription
 * @property {string} ProtocolName
 * @property {Array<Object>} ScheduledProcedureStepSequence
 */
```

## Patient / Study Enrichment

The `patient_study.enrichment_requested` webhook is sent after Avara PACS receives the first C-STORE and seeds the study. This is a **synchronous (soft) webhook** — failures, timeouts, and invalid bodies are treated as empty enrichment and do **not** hard-fail study creation.

Avara asks your EHR/RIS for demographic and study header fields to merge into AutoScribe study creation. The SDK’s `unwrap()` method returns a typed `PatientStudyEnrichmentRequestedWebhookEvent`. There is no `authorized` field; HTTP 2xx plus JSON that parses is enough. Returning `{}` is valid. Avara merges per-field with DICOM light metadata, then defaults. Do not rely on this webhook for hard access control.

```
import Avara from "avara";
import http from "node:http";


const client = new Avara();


http.createServer(async (req, res) => {
  const chunks = [];
  for await (const chunk of req) {
    chunks.push(chunk);
  }
  const body = Buffer.concat(chunks);
  const event = client.webhooks.unwrap(body, req.headers);


  if (event.type === "patient_study.enrichment_requested") {
    const { clinicId, studyInstanceUid, patientId, accessionNumber } =
      event.data;


    // This is your internal business logic
    const enrichment = await enrichPatientStudy({
      clinicId,
      studyInstanceUid,
      patientId,
      accessionNumber,
    });


    res.writeHead(200, { "Content-Type": "application/json" });
    res.end(JSON.stringify(enrichment));
  }
});


// This is your internal business logic
async function enrichPatientStudy(params) {
  // Look up demographics and study headers in your EHR/RIS
  // Return any subset of fields — or {}
  return {
    patientName: "Jane Doe",
    dateOfBirth: "1980-01-15",
    sex: "female",
    height: { value: 165, unit: "cm" },
    weight: { value: 62, unit: "kg" },
    mrn: "MRN12345",
    externalPatientId: "EHR-PT-1001",
    procedure: "CT CHEST WO CONTRAST",
    studyDescription: "CT CHEST WO CONTRAST",
    facilityName: "South Tampa Imaging",
    referringPhysicianName: "Dr. Alan Smith",
    studyDate: "2026-08-13",
    studyTime: "09:00",
    severity: "normal",
  };
}
```

**Response Format**

```
/**
 * @typedef {Object} PatientStudyEnrichmentRequestedWebhookResponse
 * @property {string} [patientName]
 * @property {string} [dateOfBirth]
 * @property {"male"|"female"|"other"} [sex]
 * @property {{value: number, unit: "in"|"cm"}} [height]
 * @property {{value: number, unit: "lbs"|"kg"}} [weight]
 * @property {string} [mrn]
 * @property {string} [externalPatientId]
 * @property {string} [procedure]
 * @property {string} [studyDescription]
 * @property {string} [facilityName]
 * @property {string} [referringPhysicianName]
 * @property {string} [studyDate]
 * @property {string} [studyTime]
 * @property {"normal"|"high"|"stat"} [severity]
 */
```

## Clinical Context Enrichment

The `clinical_context.enrichment_requested` webhook is sent when AutoScribe needs clinical context for a study (for example, a radiologist opens the study). This is a **synchronous (soft) webhook** — failures are treated as empty enrichment.

Avara asks your EHR for indication, technique, priors, and supporting documents. The SDK’s `unwrap()` method returns a typed `ClinicalContextEnrichmentRequestedWebhookEvent`. There is no `authorized` field. Returning `{}` is valid.

`data.studyId` on this event is a raw UUID v4, not a branded `stu_…` id. Most other study webhooks use `stu_…`.

`documents` are verbatim text chunks. `documentUrls` are fetched and summarized by Avara — prefer `https://` URLs.

```
import Avara from "avara";
import http from "node:http";


const client = new Avara();


http.createServer(async (req, res) => {
  const chunks = [];
  for await (const chunk of req) {
    chunks.push(chunk);
  }
  const body = Buffer.concat(chunks);
  const event = client.webhooks.unwrap(body, req.headers);


  if (event.type === "clinical_context.enrichment_requested") {
    const { clinicId, studyInstanceUid, studyId, externalPatientId, mrn } =
      event.data;


    // This is your internal business logic
    const enrichment = await enrichClinicalContext({
      clinicId,
      studyInstanceUid,
      studyId,
      externalPatientId,
      mrn,
    });


    res.writeHead(200, { "Content-Type": "application/json" });
    res.end(JSON.stringify(enrichment));
  }
});


// This is your internal business logic
async function enrichClinicalContext(params) {
  // Pull indication, technique, priors, and documents from your EHR
  // Return any subset of fields — or {}
  return {
    clinicalIndication: "Shortness of breath, evaluate for PE",
    technologistTechnique: "Helical CT chest, 1.25 mm, IV contrast",
    priorReports: [
      {
        studyDescription: "CT CHEST WO CONTRAST",
        modality: "CT",
        studyDate: "2025-11-02",
        reportText: "No acute cardiopulmonary process.",
      },
    ],
  };
}
```

**Response Format**

```
/**
 * @typedef {Object} ClinicalContextEnrichmentRequestedWebhookResponse
 * @property {string} [clinicalIndication]
 * @property {string} [technologistTechnique]
 * @property {string[]} [technologistNotes]
 * @property {Array<{externalStudyId?: string, studyDescription?: string, modality?: string, studyDate?: string, reportText: string}>} [priorReports]
 * @property {Array<{fileName: string, content: string[]}>} [documents]
 * @property {Array<{fileName?: string, url: string}>} [documentUrls]
 */
```
