Create subscription alert(s)
curl --request POST \
--url https://api.getlago.com/api/v1/subscriptions/{external_id}/alerts \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"alert": {
"code": "storage_threshold_alert",
"thresholds": [
{
"value": 99,
"code": "warn",
"notify_on": [
"triggered",
"resolved"
],
"recurring": false
}
],
"alert_type": "billable_metric_current_usage_amount",
"name": "Storage Usage Alert",
"billable_metric_code": "storage_usage"
}
}
'import requests
url = "https://api.getlago.com/api/v1/subscriptions/{external_id}/alerts"
payload = { "alert": {
"code": "storage_threshold_alert",
"thresholds": [
{
"value": 99,
"code": "warn",
"notify_on": ["triggered", "resolved"],
"recurring": False
}
],
"alert_type": "billable_metric_current_usage_amount",
"name": "Storage Usage Alert",
"billable_metric_code": "storage_usage"
} }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
alert: {
code: 'storage_threshold_alert',
thresholds: [
{
value: 99,
code: 'warn',
notify_on: ['triggered', 'resolved'],
recurring: false
}
],
alert_type: 'billable_metric_current_usage_amount',
name: 'Storage Usage Alert',
billable_metric_code: 'storage_usage'
}
})
};
fetch('https://api.getlago.com/api/v1/subscriptions/{external_id}/alerts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.getlago.com/api/v1/subscriptions/{external_id}/alerts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'alert' => [
'code' => 'storage_threshold_alert',
'thresholds' => [
[
'value' => 99,
'code' => 'warn',
'notify_on' => [
'triggered',
'resolved'
],
'recurring' => false
]
],
'alert_type' => 'billable_metric_current_usage_amount',
'name' => 'Storage Usage Alert',
'billable_metric_code' => 'storage_usage'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.getlago.com/api/v1/subscriptions/{external_id}/alerts"
payload := strings.NewReader("{\n \"alert\": {\n \"code\": \"storage_threshold_alert\",\n \"thresholds\": [\n {\n \"value\": 99,\n \"code\": \"warn\",\n \"notify_on\": [\n \"triggered\",\n \"resolved\"\n ],\n \"recurring\": false\n }\n ],\n \"alert_type\": \"billable_metric_current_usage_amount\",\n \"name\": \"Storage Usage Alert\",\n \"billable_metric_code\": \"storage_usage\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.getlago.com/api/v1/subscriptions/{external_id}/alerts")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"alert\": {\n \"code\": \"storage_threshold_alert\",\n \"thresholds\": [\n {\n \"value\": 99,\n \"code\": \"warn\",\n \"notify_on\": [\n \"triggered\",\n \"resolved\"\n ],\n \"recurring\": false\n }\n ],\n \"alert_type\": \"billable_metric_current_usage_amount\",\n \"name\": \"Storage Usage Alert\",\n \"billable_metric_code\": \"storage_usage\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.getlago.com/api/v1/subscriptions/{external_id}/alerts")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"alert\": {\n \"code\": \"storage_threshold_alert\",\n \"thresholds\": [\n {\n \"value\": 99,\n \"code\": \"warn\",\n \"notify_on\": [\n \"triggered\",\n \"resolved\"\n ],\n \"recurring\": false\n }\n ],\n \"alert_type\": \"billable_metric_current_usage_amount\",\n \"name\": \"Storage Usage Alert\",\n \"billable_metric_code\": \"storage_usage\"\n }\n}"
response = http.request(request)
puts response.read_body{
"alert": {
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"lago_organization_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"external_subscription_id": "sub_1234567890",
"lago_wallet_id": null,
"wallet_code": null,
"billable_metric": {
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"name": "Storage",
"code": "storage",
"description": "GB of storage used in my application",
"recurring": false,
"rounding_function": "round",
"rounding_precision": 2,
"created_at": "2022-09-14T16:35:31Z",
"expression": "round((event.properties.ended_at - event.properties.started_at) * event.properties.units)",
"field_name": "gb",
"aggregation_type": "sum_agg",
"weighted_interval": "seconds",
"filters": [
{
"key": "region",
"values": [
"us-east-1"
]
}
]
},
"alert_type": "billable_metric_current_usage_amount",
"code": "storage_threshold_alert",
"name": "Storage Usage Alert",
"direction": "increasing",
"previous_value": "1000.0",
"last_processed_at": "2025-05-19T10:04:21Z",
"thresholds": [
{
"code": "warn",
"notify_on": [
"triggered",
"resolved"
],
"recurring": false,
"value": "99.0"
}
],
"created_at": "2025-03-20T10:00:00Z"
}
}{
"status": 400,
"error": "Bad request"
}{
"status": 401,
"error": "Unauthorized"
}{
"status": 403,
"error": "Forbidden",
"code": "feature_unavailable"
}{
"status": 404,
"error": "Not Found",
"code": "object_not_found"
}{
"status": 422,
"error": "Unprocessable entity",
"code": "validation_errors",
"error_details": {}
}Alerts
Create an alert
This endpoint allows you to create a new alert for a subscription.
POST
/
subscriptions
/
{external_id}
/
alerts
Create subscription alert(s)
curl --request POST \
--url https://api.getlago.com/api/v1/subscriptions/{external_id}/alerts \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"alert": {
"code": "storage_threshold_alert",
"thresholds": [
{
"value": 99,
"code": "warn",
"notify_on": [
"triggered",
"resolved"
],
"recurring": false
}
],
"alert_type": "billable_metric_current_usage_amount",
"name": "Storage Usage Alert",
"billable_metric_code": "storage_usage"
}
}
'import requests
url = "https://api.getlago.com/api/v1/subscriptions/{external_id}/alerts"
payload = { "alert": {
"code": "storage_threshold_alert",
"thresholds": [
{
"value": 99,
"code": "warn",
"notify_on": ["triggered", "resolved"],
"recurring": False
}
],
"alert_type": "billable_metric_current_usage_amount",
"name": "Storage Usage Alert",
"billable_metric_code": "storage_usage"
} }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
alert: {
code: 'storage_threshold_alert',
thresholds: [
{
value: 99,
code: 'warn',
notify_on: ['triggered', 'resolved'],
recurring: false
}
],
alert_type: 'billable_metric_current_usage_amount',
name: 'Storage Usage Alert',
billable_metric_code: 'storage_usage'
}
})
};
fetch('https://api.getlago.com/api/v1/subscriptions/{external_id}/alerts', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.getlago.com/api/v1/subscriptions/{external_id}/alerts",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'alert' => [
'code' => 'storage_threshold_alert',
'thresholds' => [
[
'value' => 99,
'code' => 'warn',
'notify_on' => [
'triggered',
'resolved'
],
'recurring' => false
]
],
'alert_type' => 'billable_metric_current_usage_amount',
'name' => 'Storage Usage Alert',
'billable_metric_code' => 'storage_usage'
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.getlago.com/api/v1/subscriptions/{external_id}/alerts"
payload := strings.NewReader("{\n \"alert\": {\n \"code\": \"storage_threshold_alert\",\n \"thresholds\": [\n {\n \"value\": 99,\n \"code\": \"warn\",\n \"notify_on\": [\n \"triggered\",\n \"resolved\"\n ],\n \"recurring\": false\n }\n ],\n \"alert_type\": \"billable_metric_current_usage_amount\",\n \"name\": \"Storage Usage Alert\",\n \"billable_metric_code\": \"storage_usage\"\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.getlago.com/api/v1/subscriptions/{external_id}/alerts")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"alert\": {\n \"code\": \"storage_threshold_alert\",\n \"thresholds\": [\n {\n \"value\": 99,\n \"code\": \"warn\",\n \"notify_on\": [\n \"triggered\",\n \"resolved\"\n ],\n \"recurring\": false\n }\n ],\n \"alert_type\": \"billable_metric_current_usage_amount\",\n \"name\": \"Storage Usage Alert\",\n \"billable_metric_code\": \"storage_usage\"\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.getlago.com/api/v1/subscriptions/{external_id}/alerts")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"alert\": {\n \"code\": \"storage_threshold_alert\",\n \"thresholds\": [\n {\n \"value\": 99,\n \"code\": \"warn\",\n \"notify_on\": [\n \"triggered\",\n \"resolved\"\n ],\n \"recurring\": false\n }\n ],\n \"alert_type\": \"billable_metric_current_usage_amount\",\n \"name\": \"Storage Usage Alert\",\n \"billable_metric_code\": \"storage_usage\"\n }\n}"
response = http.request(request)
puts response.read_body{
"alert": {
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"lago_organization_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"external_subscription_id": "sub_1234567890",
"lago_wallet_id": null,
"wallet_code": null,
"billable_metric": {
"lago_id": "1a901a90-1a90-1a90-1a90-1a901a901a90",
"name": "Storage",
"code": "storage",
"description": "GB of storage used in my application",
"recurring": false,
"rounding_function": "round",
"rounding_precision": 2,
"created_at": "2022-09-14T16:35:31Z",
"expression": "round((event.properties.ended_at - event.properties.started_at) * event.properties.units)",
"field_name": "gb",
"aggregation_type": "sum_agg",
"weighted_interval": "seconds",
"filters": [
{
"key": "region",
"values": [
"us-east-1"
]
}
]
},
"alert_type": "billable_metric_current_usage_amount",
"code": "storage_threshold_alert",
"name": "Storage Usage Alert",
"direction": "increasing",
"previous_value": "1000.0",
"last_processed_at": "2025-05-19T10:04:21Z",
"thresholds": [
{
"code": "warn",
"notify_on": [
"triggered",
"resolved"
],
"recurring": false,
"value": "99.0"
}
],
"created_at": "2025-03-20T10:00:00Z"
}
}{
"status": 400,
"error": "Bad request"
}{
"status": 401,
"error": "Unauthorized"
}{
"status": 403,
"error": "Forbidden",
"code": "feature_unavailable"
}{
"status": 404,
"error": "Not Found",
"code": "object_not_found"
}{
"status": 422,
"error": "Unprocessable entity",
"code": "validation_errors",
"error_details": {}
}Authorizations
Path Parameters
Query Parameters
Filter by subscription status. When provided, the subscription is looked up with this status instead of the default active status. Possible values are pending, active, terminated, canceled, or incomplete.
Available options:
pending, active, terminated, canceled, incomplete Example:
"active"
Body
application/json
Create one or more alerts for a subscription