# Alerts ## Create `client.V1.Alerts.New(ctx, body) (*V1AlertNewResponse, error)` **post** `/v1/alerts/create` Create a new alert ### Parameters - **body:** `V1AlertNewParams` - **AlertType:** `param.Field[V1AlertNewParamsAlertType]` Type of the alert - `V1AlertNewParamsAlertType` - `V1AlertNewParamsAlertType` - `V1AlertNewParamsAlertType` - `V1AlertNewParamsAlertType` - `V1AlertNewParamsAlertType` - `V1AlertNewParamsAlertType` - `V1AlertNewParamsAlertType` - `V1AlertNewParamsAlertType` - `V1AlertNewParamsAlertType` - `V1AlertNewParamsAlertType` - `V1AlertNewParamsAlertType` - `V1AlertNewParamsAlertType` - `V1AlertNewParamsAlertType` - `V1AlertNewParamsAlertType` - **Name:** `param.Field[string]` Name of the alert - **Threshold:** `param.Field[float64]` Threshold value of the alert policy. Depending upon the alert type, this number may represent a financial amount, the days remaining, or a percentage reached. - **BillableMetricID:** `param.Field[string]` For alerts of type `usage_threshold_reached`, specifies which billable metric to track the usage for. - **CreditGrantTypeFilters:** `param.Field[[]string]` An array of strings, representing a way to filter the credit grant this alert applies to, by looking at the credit_grant_type field on the credit grant. This field is only defined for CreditPercentage and CreditBalance alerts - **CreditTypeID:** `param.Field[string]` ID of the credit's currency, defaults to USD. If the specific alert type requires a pricing unit/currency, find the ID in the [Metronome app](https://app.metronome.com/offering/pricing-units). - **CustomFieldFilters:** `param.Field[[]V1AlertNewParamsCustomFieldFilter]` A list of custom field filters for alert types that support advanced filtering. Only present for contract invoices. - **Entity:** `V1AlertNewParamsCustomFieldFiltersEntity` - `V1AlertNewParamsCustomFieldFiltersEntity` - `V1AlertNewParamsCustomFieldFiltersEntity` - `V1AlertNewParamsCustomFieldFiltersEntity` - **Key:** `string` - **Value:** `string` - **CustomerID:** `param.Field[string]` If provided, will create this alert for this specific customer. To create an alert for all customers, do not specify a `customer_id`. - **EvaluateOnCreate:** `param.Field[bool]` If true, the alert will evaluate immediately on customers that already meet the alert threshold. If false, it will only evaluate on future customers that trigger the alert threshold. Defaults to true. - **GroupValues:** `param.Field[[]V1AlertNewParamsGroupValue]` Only present for `spend_threshold_reached` alerts. Scope alert to a specific group key on individual line items. - **Key:** `string` - **Value:** `string` - **InvoiceTypesFilter:** `param.Field[[]string]` Only supported for invoice_total_reached alerts. A list of invoice types to evaluate. - **PlanID:** `param.Field[string]` If provided, will create this alert for this specific plan. To create an alert for all customers, do not specify a `plan_id`. - **UniquenessKey:** `param.Field[string]` Prevents the creation of duplicates. If a request to create a record is made with a previously used uniqueness key, a new record will not be created and the request will fail with a 409 error. ### Returns - Not supported - **Data:** `ID` ### Example ```go package main import ( "context" "fmt" "github.com/Metronome-Industries/metronome-go" "github.com/Metronome-Industries/metronome-go/option" ) func main() { client := metronome.NewClient( option.WithBearerToken("My Bearer Token"), ) alert, err := client.V1.Alerts.New(context.TODO(), metronome.V1AlertNewParams{ AlertType: metronome.F(metronome.V1AlertNewParamsAlertTypeSpendThresholdReached), Name: metronome.F("$100 spend threshold reached"), Threshold: metronome.F(10000.000000), CreditGrantTypeFilters: metronome.F([]string{"enterprise"}), CreditTypeID: metronome.F("2714e483-4ff1-48e4-9e25-ac732e8f24f2"), CustomerID: metronome.F("4db51251-61de-4bfe-b9ce-495e244f3491"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", alert.Data) } ``` ## Archive `client.V1.Alerts.Archive(ctx, body) (*V1AlertArchiveResponse, error)` **post** `/v1/alerts/archive` Archive an existing alert ### Parameters - **body:** `V1AlertArchiveParams` - **ID:** `param.Field[string]` The Metronome ID of the alert - **ReleaseUniquenessKey:** `param.Field[bool]` If true, resets the uniqueness key on this alert so it can be re-used ### Returns - Not supported - **Data:** `ID` ### Example ```go package main import ( "context" "fmt" "github.com/Metronome-Industries/metronome-go" "github.com/Metronome-Industries/metronome-go/option" ) func main() { client := metronome.NewClient( option.WithBearerToken("My Bearer Token"), ) response, err := client.V1.Alerts.Archive(context.TODO(), metronome.V1AlertArchiveParams{ ID: metronome.F("8deed800-1b7a-495d-a207-6c52bac54dc9"), }) if err != nil { panic(err.Error()) } fmt.Printf("%+v\n", response.Data) } ```