Skip to main content

Alerts - Save

Endpoint

/i/alert/save

Overview

Creates a new alert or updates an existing alert configuration.

Authentication

Pass api_key or auth_token as a query parameter, or send countly-token as a header. See Authentication.

Permissions

Requires alerts Create permission.

Request Parameters

ParameterTypeRequiredDescription
alert_configJSON String (Object)YesJSON-stringified alert configuration payload.
app_idStringConditionalRequired for non-global-admin users during create validation.
api_keyStringConditionalRequired if auth_token is not provided.
auth_tokenStringConditionalRequired if api_key is not provided.

alert_config Object Structure

FieldTypeRequiredDescription
_idStringNoExisting alert ID. If present, endpoint performs update flow.
alertNameStringConditionalRequired for create flow (_id absent).
alertDataTypeStringConditionalRequired for create flow.
alertDataSubTypeStringConditionalRequired for create flow.
selectedAppsArrayConditionalRequired for create flow; must contain at least one app ID.
enabledBooleanNoAlert enabled state.
alertValuesArrayNoAlert recipients/values for module-specific processing.
allGroupsArrayNoGroup-based targeting for recipients (module-specific).
compareTypeStringNoComparison mode (module-specific).
compareValueString or NumberNoThreshold/comparison value (module-specific).

Decoded create example:

{
"alertName": "Crash Spike",
"alertDataType": "crashes",
"alertDataSubType": "critical",
"selectedApps": ["6991c75b024cb89cdc04efd2"],
"enabled": true
}

Decoded update example:

{
"_id": "65f0cbf8bca6b8e8fbf7f901",
"enabled": false,
"compareValue": 30
}

Examples

Create alert

/i/alert/save?
app_id=6991c75b024cb89cdc04efd2&
api_key=YOUR_API_KEY&
alert_config={
"alertName":"Crash Spike",
"alertDataType":"crashes",
"alertDataSubType":"critical",
"selectedApps":["6991c75b024cb89cdc04efd2"],
"enabled":true
}

Update alert

/i/alert/save?
app_id=6991c75b024cb89cdc04efd2&
api_key=YOUR_API_KEY&
alert_config={
"_id":"65f0cbf8bca6b8e8fbf7f901",
"enabled":false,
"compareValue":25
}

Response

Success Response

Create flow:

"65f0cbf8bca6b8e8fbf7f901"

Update flow:

{
"_id": "65f0cbf8bca6b8e8fbf7f901",
"alertName": "Crash Spike",
"enabled": true
}

Validation-failure branch:

{
"result": "Not enough args"
}

Response Fields

FieldTypeDescription
(root value)StringCreated alert ID (create flow).
_idStringExisting alert ID (update flow return payload).
resultStringWrapped message value for validation/error branches.

Error Responses

  • 400
{
"result": "Missing parameter \"api_key\" or \"auth_token\""
}
  • 400
{
"result": "Missing alert_config"
}
  • 401
{
"result": "No app_id provided"
}
  • 401
{
"result": "User does not exist"
}
  • 401
{
"result": "User does not have right"
}
  • 500
{
"result": "Failed to save an alert"
}
  • 500
{
"result": "Failed to create an alertMongoServerError: duplicate key error"
}
  • 500
{
"result": "Failed to create an alert"
}

Behavior

Behavior Modes

ModeTriggerProcessing PathResponse Shape
Create alertalert_config._id is absentValidates required create fields, sets createdAt and createdBy, inserts alert.Raw root alert ID
Update alertalert_config._id presentRemoves _id from payload, sets createdBy to current member, updates matched alert.Raw previous alert document or null
Validation failRequired create fields missingStops before DB write.Wrapped { "result": "Not enough args" }

Impact on Other Data

  • Updates alert cache invalidation state so alert processor picks up create/update changes.
  • In update flow, createdBy is overwritten with the current member ID.

Limitations

  • Update flow permission is still Create (not Update) because the handler is guarded by create-permission validation.
  • Invalid update ID values can fail during ObjectId conversion and return a generic create/save error.
Implementation details

Database Collections

CollectionUsed forData touched by this endpoint
countly.membersAuthentication and permission checksReads member account and access rights for create validation.
countly.appsApp validation/context loadingValidates app_id for non-global-admin create access.
countly.alertsAlert rule persistenceInserts new alert documents or updates existing alert documents.