Set an alert
Compare a completed question result with a metric threshold.
Choose a verified question and its metricId. Use below or above with a threshold in RON as a decimal string. The comparison is strict: equality does not trigger either operator.
curl
curl -X POST "$RDC_BASE_URL/reports/v1/alerts" \
-H "Authorization: Bearer $RDC_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"operationId": "41800000-0000-4000-8000-000000000132",
"expectedRevision": 0,
"id": "revenue-below-target",
"metricId": "net-revenue",
"operator": "below",
"threshold": "190000.00",
"currency": "RON",
"questionId": "revenue-by-product",
"enabled": true
}' JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/reports/v1/alerts`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.RDC_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"operationId": "41800000-0000-4000-8000-000000000132",
"expectedRevision": 0,
"id": "revenue-below-target",
"metricId": "net-revenue",
"operator": "below",
"threshold": "190000.00",
"currency": "RON",
"questionId": "revenue-by-product",
"enabled": true
}),
});
const result = await response.json(); Python
import os
import requests
response = requests.request(
'POST',
f'{os.environ["RDC_BASE_URL"]}/reports/v1/alerts',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
json={
'operationId': '41800000-0000-4000-8000-000000000132',
'expectedRevision': 0,
'id': 'revenue-below-target',
'metricId': 'net-revenue',
'operator': 'below',
'threshold': '190000.00',
'currency': 'RON',
'questionId': 'revenue-by-product',
'enabled': True,
},
)
result = response.json() PHP
<?php
$body = <<<'JSON'
{
"operationId": "41800000-0000-4000-8000-000000000132",
"expectedRevision": 0,
"id": "revenue-below-target",
"metricId": "net-revenue",
"operator": "below",
"threshold": "190000.00",
"currency": "RON",
"questionId": "revenue-by-product",
"enabled": true
}
JSON;
$curl = curl_init(getenv('RDC_BASE_URL') . '/reports/v1/alerts');
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RDC_TOKEN'),
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => $body,
]);
$result = json_decode(curl_exec($curl), true);
curl_close($curl); C#
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/reports/v1/alerts");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
request.Content = new StringContent("""
{
"operationId": "41800000-0000-4000-8000-000000000132",
"expectedRevision": 0,
"id": "revenue-below-target",
"metricId": "net-revenue",
"operator": "below",
"threshold": "190000.00",
"currency": "RON",
"questionId": "revenue-by-product",
"enabled": true
}
""", System.Text.Encoding.UTF8, "application/json");
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"operationId": "41800000-0000-4000-8000-000000000132",
"status": "accepted",
"aggregateRevision": 1
} curl
curl "$RDC_BASE_URL/reports/v1/alerts/revenue-below-target" \
-H "Authorization: Bearer $RDC_TOKEN" JavaScript
const response = await fetch(`${process.env.RDC_BASE_URL}/reports/v1/alerts/revenue-below-target`, {
method: 'GET',
headers: {
Authorization: `Bearer ${process.env.RDC_TOKEN}`,
},
});
const result = await response.json(); Python
import os
import requests
response = requests.request(
'GET',
f'{os.environ["RDC_BASE_URL"]}/reports/v1/alerts/revenue-below-target',
headers={
'Authorization': f'Bearer {os.environ["RDC_TOKEN"]}',
},
)
result = response.json() PHP
<?php
$curl = curl_init(getenv('RDC_BASE_URL') . '/reports/v1/alerts/revenue-below-target');
curl_setopt_array($curl, [
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('RDC_TOKEN'),
],
]);
$result = json_decode(curl_exec($curl), true);
curl_close($curl); C#
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, $"{Environment.GetEnvironmentVariable("RDC_BASE_URL")}/reports/v1/alerts/revenue-below-target");
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("RDC_TOKEN"));
var response = await client.SendAsync(request);
var result = await response.Content.ReadAsStringAsync(); {
"id": "revenue-below-target",
"revision": 1,
"metricId": "net-revenue",
"operator": "below",
"threshold": "190000.00",
"currency": "RON",
"questionId": "revenue-by-product",
"enabled": true
} An alert is evaluated after a successful run, using the question filters and the account row restrictions. It does not substitute zero when a source fails or a run is incomplete.
Read the alert after the operation completes and verify threshold, operator and enabled. If query_invalid is returned, check that the question uses the metric you named. Coordinate alert recipients through the account team; this request does not create recipient addresses.