# Update an alert

> For the complete machine-readable documentation index, see [llms.txt](https://apidocs.chargebee.com/llms.txt).


[Idempotency Supported](/docs/api/idempotency)

Updates an existing alert configuration. Use this to change the `threshold` values or toggle the `status` between `enabled` and `disabled`.

### Impacts

**

Alert status on threshold change

**

When the threshold is updated for an alert, the `alarm_status` for all impacted subscriptions is reset to `within_limit`. The alert is re-evaluated the next time Chargebee processes data relevant to that alert.

**

Alert status on disable

**

When the alert `status` is changed to `disabled`, all further evaluation stops. No webhooks are fired for this alert while it is disabled. When the alert is re-enabled, the `alarm_status` is set to `within_limit` and is re-evaluated when Chargebee next processes relevant data for the alert.

## Sample Request

#### cURL

```bash
curl  https://{site}.chargebee.com/api/v2/alerts/alert___dev__3Nl7purV3LwbKYH \
     -u {site_api_key}:\
     -d "threshold[mode]"="PERCENTAGE" \
     -d "threshold[value]"=90 \
     -d status="ENABLED"
```

#### .NET

```dotnet
using ChargeBee.Api;
using ChargeBee.Models;
using ChargeBee.Models.Enums;

ApiConfig.Configure("{site}","{site_api_key}");
EntityResult result = Alert.Update("alert___dev__3Nl7purV3LwbKYH")
		.ThresholdMode(ModeEnum.Percentage)
		.ThresholdValue(90)
		.Status(Alert.StatusEnum.Enabled)
		.Request();

Alert alert = result.Alert;
```

#### Go

```go
package main
import (
    "fmt"
    "github.com/chargebee/chargebee-go/v3"
    alertAction "github.com/chargebee/chargebee-go/v3/actions/alert"
    "github.com/chargebee/chargebee-go/v3/models/alert"
    enum "github.com/chargebee/chargebee-go/v3/enum"
    alertEnum "github.com/chargebee/chargebee-go/v3/models/alert/enum"
)
func main() {
    chargebee.Configure("{site_api_key}","{site}");
    res,err := alertAction.Update("alert___dev__3Nl7purV3LwbKYH", &alert.UpdateRequestParams{
        Threshold : &alert.UpdateThresholdParams{
            Mode : enum.ModePercentage,
            Value : chargebee.Float64(90),
        },
        Status : alertEnum.StatusEnabled,
    }).Request()
    if err != nil {
        fmt.Println(err)
    } else {
        Alert := res.Alert
    }
}
```

#### Go

```go
package main

import (
  "fmt"
  "github.com/chargebee/chargebee-go/v4"
)

func main() {
  config := &chargebee.ClientConfig{
    SiteName: "{site}",
    ApiKey: "{site_api_key}",
  }    
  client := chargebee.NewClient(config)
  req := &chargebee.AlertUpdateRequest{
    Threshold : &chargebee.AlertUpdateThreshold{
        Mode : chargebee.ModePercentage,
        Value : chargebee.Float64(90),
    },
    Status : chargebee.AlertStatusTypeEnabled,
}
  res, err := client.Alert.Update("alert___dev__3Nl7purV3LwbKYH", req)
      if err != nil {
        fmt.Println(err)
    } else {
        Alert := res.Alert
    }
}
```

#### Java

```java
import com.chargebee.*;
import com.chargebee.ListResult;
import com.chargebee.models.*;
import com.chargebee.models.enums.*;
import java.io.IOException;

public class Sample {

    public static void main(String args[]) throws IOException, Exception {
        Environment.configure("{site}", "{site_api_key}");
        Result result = Alert.update("alert___dev__3Nl7purV3LwbKYH")
            .thresholdMode(Mode.PERCENTAGE)
            .thresholdValue(90.0)
            .status(Alert.Status.ENABLED)
            .request();

        Alert alert = result.alert();
    }
}
```

#### Java

```java
import com.chargebee.v4.client.ChargebeeClient;
import com.chargebee.v4.models.alert.Alert;
import com.chargebee.v4.models.alert.params.AlertUpdateParams;
import com.chargebee.v4.models.alert.responses.AlertUpdateResponse;

public class AlertUpdate {

    public static void main(String[] args) {
        ChargebeeClient client = ChargebeeClient.builder()
            .apiKey("{site_api_key}")
            .siteName("{site}")
            .build();

        AlertUpdateParams.ThresholdParams thresholdParams =
            AlertUpdateParams.ThresholdParams.builder()
                .mode(AlertUpdateParams.ThresholdParams.Mode.PERCENTAGE)
                .value(90.0)
                .build();

        AlertUpdateParams params = AlertUpdateParams.builder()
            .threshold(thresholdParams)
            .status(AlertUpdateParams.Status.ENABLED)
            .build();

        AlertUpdateResponse response = client
            .alerts()
            .update("alert___dev__3Nl7purV3LwbKYH", params);

        Alert alert = response.getAlert();
    }
}
```

#### Node.js

```node
import Chargebee from "chargebee";

const chargebee = new Chargebee({
    site: "{site}",
    apiKey: "{site_api_key}",
});

try {
    const result = await chargebee.alert.update("alert___dev__3Nl7purV3LwbKYH", {
        threshold: {
            mode: "percentage",
            value: 90
        },
        status: "enabled"
    });

    console.log(result);
    const alert = result.alert;
} catch (err) {
    console.log(err);
}
```

#### PHP

```php
<?php

require __DIR__ . '/vendor/autoload.php';

use Chargebee\ChargebeeClient;

$chargebee = new ChargebeeClient(options: [
    "site" => "{site}",
    "apiKey" => "{site_api_key}",
]);
$result = $chargebee->alert()->update("alert___dev__3Nl7purV3LwbKYH", [
    "threshold" => [
        "mode" => "percentage",
        "value" => 90
    ],
    "status" => "enabled"
]);
$alert = $result->alert;
```

#### Python

```python
import chargebee
from chargebee import Chargebee

cb_client = Chargebee(api_key="{site_api_key}", site="{site}")
response = cb_client.Alert.update("alert___dev__3Nl7purV3LwbKYH",
    cb_client.Alert.UpdateParams(
        threshold=cb_client.Alert.UpdateThresholdParams(
            mode=chargebee.Mode.PERCENTAGE,
            value=90
        ),
        status=chargebee.Alert.Status.ENABLED
    )
)
alert = response.alert
```

#### Ruby

```ruby
require 'chargebee'

ChargeBee.configure(:site => "{site}",
  :api_key => "{site_api_key}")

result = ChargeBee::Alert.update("alert___dev__3Nl7purV3LwbKYH",{
  :threshold => {
    :mode => "PERCENTAGE",
    :value => 90
  },
  :status => "ENABLED"
})

alert = result.alert
```

## Sample Response

```json
{
  "alert": {
    "id": "alert___dev__3Nl7purV3LwbKYH",
    "name": "GPT-4o usage threshold",
    "description": "Notify when usage crosses 90% of quota",
    "type": "usage_exceeded",
    "metered_feature_id": "gpt4o-usage",
    "threshold": {
      "mode": "percentage",
      "value": 90
    },
    "filter_conditions": null,
    "subscription_id": "sub_KyV2S7Qm8tL7p",
    "status": "enabled",
    "object": "alert",
    "resource_version": 1763884000000,
    "created_at": 1763879971,
    "updated_at": 1763884000
  }
}
```

## URL Format

**POST** https://[site].chargebee.com/api/v2/alerts/{alert-id}

## Input Parameters

- `status` (optional, enumerated string, default=enabled)
  Set to `enabled` to activate the alert or `disabled` to deactivate it.
  Possible enum values:
    - `enabled`
      The alert is active and will trigger when the threshold is breached.
    - `disabled`
      The alert is inactive and will not trigger.

- `threshold` (optional, enumerated string)
  The threshold configuration that defines when this alert fires. Only the fields provided are updated.
  - `mode` (optional, enumerated string)
    How the threshold `value` is interpreted. `usage_exceeded` alerts support `percentage` or `absolute`. `spend_exceeded` and `credit_balance_dropped` alerts always use `absolute`.
    Possible enum values:
      - `absolute`
        The threshold `value` represents an absolute quantity: a usage quantity for `usage_exceeded`, an overage spend amount in `currency_code` for `spend_exceeded`, or a credit-balance floor for `credit_balance_dropped`.
      - `percentage`
        The threshold `value` represents a percentage (0-100) of the plan or feature quota. Supported only for `usage_exceeded` alerts.
  - `value` (optional, double)
    The numeric threshold at which the alert fires. For `percentage` mode, this must be between 0 and 100 inclusive. For `absolute` mode, this must be >= 0.

## Returns

- `alert` (Alert object)
  Resource object representing alert.
