Widget API Reference
Complete schemas, field types, and validation rules for the Partner Widget postMessage API.
This page documents every field Scribeberry accepts and emits for the Partner Widget. For setup and a working example, see Partner Widget.
All postMessage payloads are JSON objects with a required type string. Always verify event.origin === 'https://app.scribeberry.com' (or your configured Scribeberry host) before handling messages.
HTTP: Token endpoint
Mint session tokens server-side only. Never expose your partner key to the browser.
Request body
| Field | Required | Type | Description |
|---|---|---|---|
userEmail | Yes | string | Valid email address. Used to create or link the clinician's Scribeberry account. |
emrUserId | Yes | string | Your stable identifier for this clinician (min length 1). |
emrSessionId | No | string | Your session or encounter identifier. When provided, Scribeberry reopens the same scribe on relaunch. Omit only if clinicians should pick scribes manually. |
Success response
| Field | Type | Description |
|---|---|---|
token | string | JWT for the iframe ?token= query parameter. Default expiry is 24 hours. |
expiresAt | string | ISO 8601 expiry timestamp. |
Common HTTP errors
| Status | Meaning |
|---|---|
401 | Missing or invalid X-Partner-Key header |
400 | Invalid request body (e.g. malformed userEmail) |
429 | Rate limited (20 requests/minute per IP) |
EMR → Scribeberry messages
PATIENT_CONTEXT
Send when the chart opens or when the active patient, encounter, or clinical context changes.
patient (WidgetPatient)
| Field | Required | Type | Description |
|---|---|---|---|
id | Yes | string | Your stable patient identifier (non-empty after trimming). Returned on PUSH_NOTE.patientId and PUSH_DOCUMENT.patientId. Use the same id your EMR uses to route notes back to the chart. |
name | Yes | string | Patient full name (non-empty after trimming). |
firstName | No | string | First name. If omitted, parsed from name. |
lastName | No | string | Last name. If omitted, parsed from name. |
dob | No | string | Date of birth. Recommended format: YYYY-MM-DD. |
gender | No | enum | One of male, female, other, unknown. Case-insensitive — "Male" is accepted and normalized to "male". |
healthCardNumber | No | string | Provincial health number / PHN. |
email | No | string | Valid email address, or empty string "". |
phone | No | string | Contact phone number. |
Example — minimum valid patient:
Example — full demographics:
context (WidgetMedicalContext)
All fields are optional. Omit the entire context object if you have no clinical data to send.
| Field | Type | Description |
|---|---|---|
allergies | WidgetAllergy[] | Known allergies |
medications | WidgetMedication[] | Current medications |
diagnoses | WidgetDiagnosis[] | Active or historical diagnoses |
labResults | WidgetLabResult[] | Recent lab values |
chiefComplaint | string | Reason for visit |
medicalHistory | string | Free-text past medical history |
customData | object | Arbitrary key/value data for your integration |
allergies[]
| Field | Required | Type | Description |
|---|---|---|---|
name | Yes | string | Allergen name |
severity | No | enum | mild, moderate, or severe (case-insensitive) |
reaction | No | string | Reaction description |
medications[]
| Field | Required | Type | Description |
|---|---|---|---|
name | Yes | string | Medication name |
dosage | No | string | Dose (e.g. "500mg BID") |
frequency | No | string | Frequency |
startDate | No | string | Start date |
status | No | enum | active or discontinued (case-insensitive) |
diagnoses[]
| Field | Required | Type | Description |
|---|---|---|---|
name | Yes | string | Diagnosis description |
code | No | string | Code value (e.g. ICD-10) |
codeSystem | No | string | Code system (e.g. "ICD-10") |
date | No | string | Diagnosis date |
status | No | enum | active or resolved (case-insensitive) |
labResults[]
| Field | Required | Type | Description |
|---|---|---|---|
name | Yes | string | Test name |
value | No | string | Result value |
unit | No | string | Unit of measure |
date | No | string | Collection or result date |
normalRange | No | string | Reference range |
appointment (WidgetAppointment)
| Field | Required | Type | Description |
|---|---|---|---|
id | No | string | Your appointment identifier |
dateTime | No | string | ISO 8601 datetime |
type | No | string | Visit type (e.g. "Follow-up") |
duration | No | number | Duration in minutes |
reason | No | string | Appointment reason |
noteConfig (WidgetNoteConfig)
Define the shape of structured note output. When provided, template selection is locked to the resolved template for these section labels.
| Field | Required | Type | Description |
|---|---|---|---|
sections | Yes | array | 1–20 ordered sections |
Each section:
| Field | Required | Type | Description |
|---|---|---|---|
key | Yes | string | 1–64 chars. Must match /^[a-zA-Z][a-zA-Z0-9_]*$/. Returned as the key in PUSH_NOTE.sections. |
label | Yes | string | 1–128 chars. Heading label used for note generation and template resolution. |
Classic SOAP labels (Subjective, Objective, Assessment, Plan) resolve to Scribeberry's curated SOAP template. Other label sets get a synthetic heading-based template. If noteConfig is omitted, SOAP is used.
SET_CONTEXT
Append or replace free-text context outside the structured context object.
TOKEN_REFRESH
Extend the session without reloading the iframe.
CLOSE_WIDGET
Signal that the user left the chart. Scribeberry may tear down active state.
Scribeberry → EMR messages
WIDGET_READY
Widget loaded and ready to receive PATIENT_CONTEXT.
SESSION_STARTED
Sent when an encounter-scoped scribe opens or resumes (emrSessionId was included in the token).
PUSH_NOTE
Clinician sent a generated note to your EMR.
Notes can be sent multiple times per session (e.g. after edits).
PUSH_DOCUMENT
Clinician sent a document (letter, referral, form, or PDF).
REQUEST_PATIENT_CONTEXT
Widget needs current patient data. Respond with PATIENT_CONTEXT.
TOKEN_EXPIRING
Token will expire soon. Mint a new token and send TOKEN_REFRESH.
REQUEST_TOKEN_REFRESH
Widget is actively requesting a new token. Respond with TOKEN_REFRESH.
TOKEN_EXPIRED
Token has expired. Reload the iframe with a new token.
WIDGET_ERROR
Validation or processing error. Handle this in your postMessage listener.
| Code | When |
|---|---|
INVALID_PATIENT_DATA | PATIENT_CONTEXT.patient failed validation |
The message field contains field-level details, for example:
Common validation failures:
| Issue | Fix |
|---|---|
Missing patient.id | Include your EMR's stable patient identifier |
Missing patient.name | Include the patient's full name |
Invalid gender | Use male, female, other, or unknown (any casing) |
Invalid email | Provide a valid email or omit the field |
Invalid noteConfig.sections[].key | Keys must start with a letter and contain only letters, digits, and underscores |
Patient ID semantics
patient.idis your EMR identifier. Scribeberry echoes it onPUSH_NOTE.patientIdso you can file notes back to the correct chart row.- Internally, Scribeberry namespaces widget patients as
widget_{partnerId}_{patientId}for conversation grouping. Your raw id is never used as a Scribeberry account patient UUID. - Use stable ids — auto-increment integers are fine as long as they are unique within your EMR and consistent across sessions for the same person.
Enum normalization
These string enums are case-insensitive. Values are trimmed and lowercased before validation:
| Field | Accepted values |
|---|---|
patient.gender | male, female, other, unknown |
context.allergies[].severity | mild, moderate, severe |
context.medications[].status | active, discontinued |
context.diagnoses[].status | active, resolved |
Unrecognized enum values fail validation with a field-level error in WIDGET_ERROR.message.