Skip to content
Engine API

Alert Rules

Alert Rules endpoints of the MedHook engine API: 8 operations with parameters, schemas and a curl example for each.

On this page

Rules that notify someone when messages fail.

List alert rules

get/api/alert-rules

Alert rules in the caller's workspace, the workflows a rule can watch, and which channels this engine can deliver to. channels.email is true when the engine has a mail transport (ENGINE_EMAIL_FROM with RESEND_API_KEY or ENGINE_EMAIL_WEBHOOK_URL); channels.sms is true when Text (SMS) is connected in Settings > Notifications. Each rule carries severity (critical, error, warning or info; PagerDuty's payload.severity) and the priority it maps to (P1 critical, P2 error, P3 warning or info), firing, lastFiredAt and lastResolvedAt. A per-sender rule (senderScope) also carries quietSenders: each sender quiet now, its quietFor, lastSeenAt and whether its alert was delivered (notified). firing means a trigger notification was delivered and no resolve has been delivered since: a failed send leaves it unchanged, shows notifyError, and is retried with backoff (30 s doubling to 15 min). When the condition clears, a resolve is sent (PagerDuty resolves the incident by the same dedup_key; Slack says RESOLVED; webhooks get status: resolved). There is no repeat while a rule stays firing.

Minimum role: viewer.

Auth: Bearer token (how to get one) · Operation: listAlertRules

Parameters

NameInTypeDescription
workflowIdquerystring

Only the rules watching this workflow, including rules that watch every workflow, and only it among the workflow options (the workflow home's Settings tab).

Responses

  • 200The rules, the workflows a rule can watch, and the channels available.
    Response fields

    application/json · object

    • rulesarray of object
    • workflowsarray of object
      2 fields
      • idstring
      • namestring
    • channelsobject
      2 fields
      • emailboolean

        This engine has a mail transport for email alerts.

      • smsboolean

        Text (SMS) is connected in Settings > Notifications, so text rules can send.

  • 401No credential, or the token is invalid or expired.

    application/json · ApiError

  • 500Unexpected server error.

    application/json · ApiError

Example request

curl
curl "$ENGINE_URL/api/alert-rules" \
  -H "Authorization: Bearer $TOKEN"

Create an alert rule

post/api/alert-rules

Creates a rule. The notify target is encrypted and write-only: reads never return it. notifyChannel is pagerduty, slack, webhook, email, sms or teams. An sms rule's target is an E.164 number (like +12175550100) and it sends through the connected Text (SMS) channel (the customer's Twilio); a teams rule's target is a Microsoft Teams incoming webhook (https only, checked against private and link-local addresses before each send). An enabled email rule is refused with 400 (EMAIL_NOT_CONFIGURED on notifyChannel) when the engine has no mail transport; an enabled text rule is refused with 400 (SMS_NOT_CONNECTED, a message on notifyChannel) when Text (SMS) has never been connected on this engine (one whose channel was disconnected falls back to email, so it is allowed). Optional severity (critical, error, warning, info) defaults to error; or send priority instead (P1, P2 or P3, stored as critical, error or warning; 400 on priority when it disagrees with a severity sent beside it). During on-call quiet hours a P2 or P3 rule's trigger waits until they end; P1 always pages. A queue_size rule may add oldestMinutes (1 to 1440): it also fires when the queue's oldest waiting item is older than that ("over 100 or older than 15 min"); other kinds refuse it. A no_messages rule may add senderScope: each watches every sender (MSH-4) seen in the last senderLookbackDays days (1 to 30, default 7), one watches the sender named in sender; windowSeconds is how long a sender may be quiet. Each quiet sender is its own incident: its own trigger and resolve, with a PagerDuty dedup_key per sender, and an alert that names the sender and how long it has been quiet. With active hours, only quiet time inside them counts. Each rule read back carries when, the condition in plain English for the rules table.

Minimum role: operator.

Auth: Bearer token (how to get one) · Operation: createAlertRule

Request body (required)

application/json · object

Responses

  • 201Created.
    Response fields

    application/json · object

    • ruleobject
  • 400The request is malformed or fails validation.

    application/json · ApiError

  • 401No credential, or the token is invalid or expired.

    application/json · ApiError

  • 500Unexpected server error.

    application/json · ApiError

Example request

curl
curl -X POST "$ENGINE_URL/api/alert-rules" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{}'

Update an alert rule

put/api/alert-rules/{id}

Changes any subset of the fields. The engine validates the result as a whole, with the same channel checks as create (EMAIL_NOT_CONFIGURED, SMS_NOT_CONNECTED; notifyChannel may be sms or teams). Renaming a firing rule, changing its condition, channel or target sends a resolve for the open incident under the old settings and starts the rule quiet again.

Minimum role: operator.

Auth: Bearer token (how to get one) · Operation: updateAlertRule

Parameters

NameInTypeDescription
idrequiredpathstring

Rule id.

Request body (required)

application/json · object

Responses

  • 200Updated.
    Response fields

    application/json · object

    • ruleobject
  • 400The request is malformed or fails validation.

    application/json · ApiError

  • 401No credential, or the token is invalid or expired.

    application/json · ApiError

  • 404Not found in the caller's workspace.

    application/json · ApiError

  • 500Unexpected server error.

    application/json · ApiError

Example request

curl
curl -X PUT "$ENGINE_URL/api/alert-rules/<id>" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{}'

Delete an alert rule

delete/api/alert-rules/{id}

Deletes the rule.

Minimum role: operator.

Auth: Bearer token (how to get one) · Operation: deleteAlertRule

Parameters

NameInTypeDescription
idrequiredpathstring

Rule id.

Responses

  • 200Deleted.
    Response fields

    application/json · object

    • deletedboolean
  • 401No credential, or the token is invalid or expired.

    application/json · ApiError

  • 404Not found in the caller's workspace.

    application/json · ApiError

  • 500Unexpected server error.

    application/json · ApiError

Example request

curl
curl -X DELETE "$ENGINE_URL/api/alert-rules/<id>" \
  -H "Authorization: Bearer $TOKEN"

List recent senders

get/api/alert-rules/senders

Senders (MSH-4.1, uppercased as message search stores them) seen in the last 7 days in the caller's workspace, newest first, for a per-sender rule's sender picker. Sender names and times only, never message content.

Minimum role: viewer.

Auth: Bearer token (how to get one) · Operation: listAlertRuleSenders

Parameters

NameInTypeDescription
workflowIdquerystring

Only senders to this workflow.

Responses

  • 200The senders.
    Response fields

    application/json · object

    • sendersarray of object
      2 fields
      • senderstring
      • lastSeenAtstring
  • 400The request is malformed or fails validation.

    application/json · ApiError

  • 401No credential, or the token is invalid or expired.

    application/json · ApiError

  • 500Unexpected server error.

    application/json · ApiError

Example request

curl
curl "$ENGINE_URL/api/alert-rules/senders" \
  -H "Authorization: Bearer $TOKEN"

Send a test message

post/api/alert-rules/{id}/test

Sends one [TEST] message through the rule's saved channel and target. Admin only; audited (alert_rule.test_sent). A failed delivery answers 502 with the error, URLs removed. Rate limited: 10 req / 60 s.

Minimum role: admin.

Auth: Bearer token (how to get one) · Operation: testAlertRule

Parameters

NameInTypeDescription
idrequiredpathstring

Rule id.

Responses

  • 200Delivered.
    Response fields

    application/json · object

    • okboolean
    • channelstring
  • 400The request is malformed or fails validation.

    application/json · ApiError

  • 401No credential, or the token is invalid or expired.

    application/json · ApiError

  • 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).

    application/json · ApiError

  • 404Not found in the caller's workspace.

    application/json · ApiError

  • 502Error.

    application/json · ApiError

Example request

curl
curl -X POST "$ENGINE_URL/api/alert-rules/<id>/test" \
  -H "Authorization: Bearer $TOKEN"

Test an alert rule against history

post/api/alert-rules/dry-run

Replays an unsaved rule against the last 30 days of stored executions and says how many times it would have fired.

Minimum role: operator.

Auth: Bearer token (how to get one) · Operation: dryRunAlertRule

Request body (required)

application/json · object

Responses

  • 200The result.

    application/json · object

  • 400The request is malformed or fails validation.

    application/json · ApiError

  • 401No credential, or the token is invalid or expired.

    application/json · ApiError

  • 500Unexpected server error.

    application/json · ApiError

Example request

curl
curl -X POST "$ENGINE_URL/api/alert-rules/dry-run" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{}'

Add one of the workflow's Settings alerts

post/api/workflows/{id}/alert-rules

Creates one of the four alerts the workflow home's Settings › Alerts shows, with its values: error_rate (> 1% over 10 min), no_messages (none for 30 min, only between 07:00 and 19:00 in timezone), queue_size (> 100 waiting longer than 5 min) or secret_expiring (14 days before a certificate on one of the workflow's connections, or a Secret Manager secret, expires). It is emailed to the workflow's Owner, else its creator: 400 when neither is an email address or the engine has no mail transport (EMAIL_NOT_CONFIGURED). One rule per kind per workflow: 409 when one exists. The rule is named {Label} · {workflow name}, with the next free (n) when another rule holds that name. The address is sealed like any notify target and never returned: the rule's notifyLabel is owner. Edits go through PUT /api/alert-rules/{id}. Audited as alert_rule.created with source: workflow_settings. Rate limited to 30 requests per minute.

Minimum role: operator.

Auth: Bearer token (how to get one) · Operation: createWorkflowAlertRule

Parameters

NameInTypeDescription
idrequiredpathstring

Workflow id.

Request body (required)

application/json · object

  • kindstringrequired

    One of: "error_rate", "no_messages", "queue_size", "secret_expiring"

  • timezonestring

    IANA time zone for the Silence hours, e.g. "America/Chicago". Default UTC.

Responses

  • 201Created.
    Response fields

    application/json · object

    • ruleobject

      The rule, as GET /api/alert-rules lists it.

  • 400The request is malformed or fails validation.

    application/json · ApiError

  • 401No credential, or the token is invalid or expired.

    application/json · ApiError

  • 403The caller's role, license or network address does not allow this. A signed-in person who is not a member of the requested workspace gets code `WORKSPACE_FORBIDDEN`; a viewer asking for message content gets `PHI_FORBIDDEN` (or `PHI_SEARCH_FORBIDDEN` for a search on message content).

    application/json · ApiError

  • 404Not found in the caller's workspace.

    application/json · ApiError

  • 409The request conflicts with the current state.

    application/json · ApiError

  • 429Rate limit exceeded (see the `Retry-After` header), or on the AI routes the daily AI budget is used up.

    application/json · ApiError

  • 500Unexpected server error.

    application/json · ApiError

Example request

curl
curl -X POST "$ENGINE_URL/api/workflows/<id>/alert-rules" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "kind": "error_rate",
  "timezone": "string"
}'

Schemas

Named objects the operations above link to.

ApiError

The error body. error is always present. code is present on most errors and is the field to branch on; a few routes and the sign-in and role checks return only error (and sometimes detail).

  • errorstringrequired

    Human-readable error message.

  • codestring

    Machine-readable error code.

    One of: "BAD_REQUEST", "INVALID_REQUEST", "UNAUTHORIZED", "UNAUTHENTICATED", "FORBIDDEN", "NOT_FOUND", "CONFLICT", "UNPROCESSABLE_ENTITY", "RATE_LIMITED", "INTERNAL_ERROR", "SERVICE_UNAVAILABLE", "NOT_CONFIGURED", "SIGNATURE_REQUIRED", "INVALID_SIGNATURE", "TIMESTAMP_REQUIRED", "TIMESTAMP_INVALID", "TIMESTAMP_OUT_OF_TOLERANCE", "INVALID_CREDENTIALS", "INVALID_TOKEN", "PAYLOAD_TOO_LARGE", "INVALID_NDJSON", "PHI_NOT_AUTHORIZED", "PHI_IN_SANDBOX", "IN_PROGRESS", "RETRY_SCHEDULED", "WORKFLOW_DISABLED", "CONFLICTING_SCOPE", "ALREADY_DELIVERED", "CHAIN_TOO_DEEP", "NO_FAILED_DESTINATION", "STALE_SCOPE", "UNKNOWN_DESTINATION", "NO_DESTINATIONS", "NOT_A_MESSAGE", "AI_FEATURES_DISABLED"

  • detailsany

    Optional structured context about the error.