This article provides sample API calls for retrieving triggered Alerts, creating and updating Alert Rules, and managing User subscriptions to Alert Rules:
/api/metric_alert: Retrieve triggered Alerts for a Metric, dismiss, activate, re-send, or send the Alert to phone./api/alert_rule/: Retrieve, create, and update Alert Rules./api/alert_rule_user_share: Retrieve User Alerts, subscribe, and unsubscribe User from Alerts.
Prerequisites:
- Set up API access, verify that you have API access, and obtain a token via the get_token call OR
- Generate Personal API Token.
Table of Contents
1. Access Admin > System > API Toolkit
2. Configure Triggered Alerts
2.1. Retrieve Triggered Alerts for a Metric
A GET request to /api/metric_alert returns the alerts that have fired for a Metric.
NOTE: The result may be empty if no alerts have triggered.
- Item: metric_alert
- Method: GET
- Filter the results with the following parameters:
- element: The element (Metric) ID. Find it in the element editor URL:
https://docs.metricinsights.com/editor/element/metric/152743#data
- dimension_value: (Optional) The Dimension Value ID to filter by.
- start_time / end_time: (Optional) Restrict alerts to a date range. Accepts
YYYY-MM-DDorYYYY-MM-DD HH:MM:SS.
- Enter an API Token.
- [Run request]
Example Response
{
"metric_alerts": [
{
"id": 90187,
"element": 284,
"dimension_value": -1,
"alert_rule": 1442,
"text": "Revenue is above the target of 1,000,000",
"measurement_time": "2026-06-01 00:00:00",
"alert_status": "Active"
}
]
}
Fields Description
| Field Name | Value Type | Description |
|---|---|---|
id | integer | The ID of the triggered alert (alert event). |
element | integer | The element (Metric) ID. |
dimension_value | integer | The Dimension Value ID. -1 represents all Dimension Values. |
alert_rule | integer | The ID of the Alert Rule that fired. |
text | string | The alert message text. |
measurement_time | datetime | The measurement time the alert is associated with. |
alert_status | string | The alert's status. ("Active", "Dismissed") |
NOTES:
- Add html="Y" to also return a text_html field, or json="Y" to return the raw alert payload as JSON.
- Add visualization_source="Y" to include dimension_name, alert_rule_name, and visualization-source fields.
2.2. Act on a Triggered Alert
A PUT request to /api/metric_alert/id/<id> performs an action on a triggered alert. The action is specified with the call parameter.
- Item: metric_alert
- Method: PUT
- Enter the Alert Event ID
- See the Retrieve Triggered Alerts for a Metric section.
- call: The action to perform:
- dismiss: Dismiss the alert for the current user.
- activate: Re-activate a dismissed alert.
- resend: Resend the alert (Admin only).
- send_to_phone: Send the alert as a mobile notification. Optional report (report ID); Admins may also pass user to send on another user's behalf.
- Enter an API Token.
- [Run request]
3. Configure Alert Rules
3.1. Retrieve Alert Rules
A GET request to /api/alert_rule returns the configured Alert Rules.
- Item: alert_rule
- Method: GET
- Filter the results with the following parameters:
- element: Return rules for this element (Metric) ID.
- report: Return rules for this report ID.
- personal: Set to "
Y" to return only personal (KPI) alert rules.
- Enter an API Token.
- [Run request]
The response lists each rule's id, name, element, report, alert_rule_type, type, and condition fields (see the parameter table in the Create or Update an Alert Rule section), plus last_updated_time and creator.
3.2. Create or Update an Alert Rule
- A POST request to
/api/alert_rulecreates a new Alert Rule. - A PUT request to
/api/alert_rule/id/<id>updates an existing rule.
- Item: alert_rule
- Method: Select POST to create a new, or PUT to update an exsiting Alert Rule.
- Enter the existing Alert Rule ID (for POST), or the ID of the Alert Rule that needs to be updated (for PUT).
- See the Retrieve Alert Rules section.
- Select JSON request and enter values.
- See the Alert Rule Fields section for details.
- Enter an API Token.
- [Run request]
Alert Rule Types and Fields
This table displays available Alert Rule Types (alert_rule_type) and condition types that trigger the Alers (type).
| alert_rule_type | Supported type values |
|---|---|
user (KPI) | fixed value, prior value, average, volatility band, target, compound |
global (Global) | fixed value, prior value, average, volatility band, stoplight, unusual value, best ever, worst ever |
| Field Name | Type | Description |
|---|---|---|
name | string | A unique, user-defined name for the alert. |
element | integer | The element (Metric) ID the alert is created for. |
report | integer | The report ID the alert is created for. |
type | enum | The condition type that triggers the alert.
|
alert_rule_type | enum | KPI vs Global alert. |
alert_visibility | enum | Whether the alert is visible to everyone with access to the Metric, or only to the current user. |
assign_type | enum | The entity the alert is assigned to. |
send_alert_to_phone | enum | Send the alert as a mobile notification. (Y, N) |
comparison_type | enum | The comparison that triggers the alert. (fixed, pct variance, less fixed, less pct variance) |
comparison_interval_compare_to_period | enum | The period to compare to. (hour, day, week, month, quarter, year) |
comparison_interval_period | enum | The period whose values are compared. (hour, day, week, month, quarter, year) |
comparison_interval | integer | How many comparison periods to consider. |
percentage_comparison_type | enum | Percentage comparison operator. (above, above or equal, below, below or equal, above or below, within, between, equal) |
comparison_fixed_value | float | The fixed value the condition is applied to. |
comparison_fixed_value_upper_bound | float | The upper bound of a value range. |
comparison_percentage_tolerance | float | The percentage above/below which the alert is created. |
range_of_values_scope | enum | The value condition for the alert. (above, below, above or below) |
compare_line | integer | The compare line ID. |
target | integer | The Target ID. Required for type = target. |
immediate_notification_ind | enum | "Y" = send immediately, "N" = email digest, "None" = browser
only. |
send_notification_via | enum | How the notification is sent. (email, sms, phone_alert) |
trigger_alert_when | enum | When the alert is sent. (first time only, every time) |
4. Manage User Subscriptions to Alert Rules
The /api/alert_rule_user_share endpoint manages which Users are subscribed to which Alert Rules. Each record represents a single User-to-Alert-Rule subscription.
4.1. View User Subscriptions
- A GET request to
/api/alert_rule_user_sharereturns the Alert Rule-to-User subscription mappings. - A GET request to
/api/alert_rule_user_share/id/<id>returns the specified Alert Rue-to-User mapping.
- Item: alert_rule_user_share
- Method: GET
- Filter the results with the following parameters:
- alert_rule: The ID of the Alert Rule.
- user: The ID of the User.
- Leave both empty to return all mappings.
- Enter an API Token.
- [Run request]
4.2. Subscribe a User to an Alert Rule
A POST request to /api/alert_rule_user_share subscribes a User to an Alert Rule.
- Item: alert_rule_user_share
- Method: POST
- Enter the ID of an already existing Aler Rule-to-User mapping.
- See Retrieve Alert Rules for details.
- Choose JSON request and provide the following values:
- alert_rule: The Alert Rule ID
- user: The User ID
- Enter an API Token.
- [Run request]
4.3. Unsubscribe a User from an Alert Rule
A DELETE request to /api/alert_rule_user_share/id/<id> removes a User's subscription to an Alert Rule.
- Item: alert_rule_user_share
- Method: DELETE
- Enter the ID of the subscription to be deleted.
- See the View User Subscriptions section for details.
- Enter an API Token.
- [Run request]