Metering
Update Usage Alert
Re-aim an existing usage alert at a new threshold type and value.
PUT
/
v1
/
usage-alerts
/
{id}
Edit a usage alert's threshold
curl --request PUT \
--url https://billing.example.com/v1/usage-alerts/{id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"threshold": 123
}
'import requests
url = "https://billing.example.com/v1/usage-alerts/{id}"
payload = { "threshold": 123 }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({threshold: 123})
};
fetch('https://billing.example.com/v1/usage-alerts/{id}', 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://billing.example.com/v1/usage-alerts/{id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'threshold' => 123
]),
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://billing.example.com/v1/usage-alerts/{id}"
payload := strings.NewReader("{\n \"threshold\": 123\n}")
req, _ := http.NewRequest("PUT", 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.put("https://billing.example.com/v1/usage-alerts/{id}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"threshold\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/usage-alerts/{id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"threshold\": 123\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"subscription_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"metric_code": "<string>",
"threshold_type": "quantity",
"threshold": 123,
"last_fired_period_start": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}Changes the threshold an alert fires at. The subscription and metric are
the alert’s identity — to point an alert at a different subscription or
metric, delete it and
create a new one. Updating clears the
alert’s per-period “already fired” marker (
Errors use the standard envelope — see Errors.
last_fired_period_start), so
the new threshold can fire in the current billing period even if the old
one already did.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
id | string (UUID) | Yes | Usage alert ID (path). Must belong to your tenant |
Request Body
| Parameter | Type | Required | Description |
|---|---|---|---|
threshold_type | string | Yes | quantity (an absolute metered quantity) or percent_of_limit (a percentage of the subscription’s entitlement limit) |
threshold | integer | Yes | Must be greater than 0. For percent_of_limit at most 1000; values above 100 alert on overage |
Example Request
curl -X PUT https://api.recurso.dev/v1/usage-alerts/a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"threshold_type": "percent_of_limit",
"threshold": 90
}'
Response
The response echoes the alert’sid and the new threshold. The handler
does not re-read the row after the update, so subscription_id,
metric_code, created_at and updated_at come back zero-valued here —
use List Usage Alerts to read the full
object.
{
"data": {
"id": "a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d",
"tenant_id": "2b9e1c44-7d3a-4f6b-8e21-5c0d9a7f1b33",
"subscription_id": "00000000-0000-0000-0000-000000000000",
"metric_code": "",
"threshold_type": "percent_of_limit",
"threshold": 90,
"created_at": "0001-01-01T00:00:00Z",
"updated_at": "0001-01-01T00:00:00Z"
}
}
Fields
| Field | Type | Description |
|---|---|---|
id | string (UUID) | The alert that was updated |
tenant_id | string (UUID) | Owning tenant |
threshold_type | string | The new quantity or percent_of_limit |
threshold | integer | The new threshold value |
subscription_id, metric_code, created_at, updated_at | — | Not populated by this endpoint (see above); last_fired_period_start is omitted because the update resets it to null |
Errors
| Status | Code | When | Fix |
|---|---|---|---|
400 | validation_failed | id is not a valid UUID, or the body is malformed / missing threshold_type or threshold | Pass the alert’s UUID and both required fields |
400 | validation_failed | threshold_type is not quantity or percent_of_limit | Use one of the two values |
400 | validation_failed | threshold is not positive, or a percent_of_limit threshold exceeds 1000 | Send a positive integer (percent thresholds at most 1000) |
401 | unauthorized | Missing or invalid API key / session | Send Authorization: Bearer $API_KEY |
404 | not_found | No usage alert with that ID in your tenant | Check the ID against List Usage Alerts |
409 | conflict | Another alert on the same subscription and metric already has this exact threshold | Edit or delete the duplicate instead |
500 | internal_error | Persisting the update failed | Retry; contact support if it persists |
Authorizations
Tenant API key obtained from POST /auth/register or POST /v1/developer/keys.
Path Parameters
Body
application/json
Response
The updated alert
A usage threshold that fires once per billing period.
Show child attributes
Show child attributes
⌘I
Edit a usage alert's threshold
curl --request PUT \
--url https://billing.example.com/v1/usage-alerts/{id} \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"threshold": 123
}
'import requests
url = "https://billing.example.com/v1/usage-alerts/{id}"
payload = { "threshold": 123 }
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.put(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'PUT',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({threshold: 123})
};
fetch('https://billing.example.com/v1/usage-alerts/{id}', 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://billing.example.com/v1/usage-alerts/{id}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "PUT",
CURLOPT_POSTFIELDS => json_encode([
'threshold' => 123
]),
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://billing.example.com/v1/usage-alerts/{id}"
payload := strings.NewReader("{\n \"threshold\": 123\n}")
req, _ := http.NewRequest("PUT", 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.put("https://billing.example.com/v1/usage-alerts/{id}")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"threshold\": 123\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://billing.example.com/v1/usage-alerts/{id}")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Put.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"threshold\": 123\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"subscription_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a",
"metric_code": "<string>",
"threshold_type": "quantity",
"threshold": 123,
"last_fired_period_start": "2023-11-07T05:31:56Z",
"created_at": "2023-11-07T05:31:56Z",
"updated_at": "2023-11-07T05:31:56Z"
}
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}{
"error": {
"code": "validation_failed",
"message": "<string>"
}
}