# Update a rule (/docs/api-reference/risk/update-risk-rule)

Changes the fields given; `conditions` replaces the whole list.

`PATCH https://api.coss.com/v1/risk/rules/{id}`

Authenticate with your API key as a bearer token (`Authorization: Bearer coss_test_…`). Responses are JSON with snake_case fields; errors are `{ error: { type, code, message, param?, issues?, request_id } }` (https://coss.com/docs/api-reference/errors.md).

## Path parameters

- `id` (string, required): The rule's id.

## Request body

- `name` (string, 1-100 characters): Your name for the rule.
- `enabled` (boolean): `false` keeps it, and stops applying it.
- `position` (integer, 0-10000): Rules are tried in ascending order.
- `events` (("signup" | "login" | "message" | "checkout" | "custom")[], at most 5 items): Events it applies to. Empty: every event.
- `match` ("all" | "any"): `all`: every condition must hold. `any`: one is enough.
- `conditions` (object[], 1-20 items): What must hold, by `match`.
  - `field` (string, required, one of "email.valid", "email.disposable", "email.undeliverable", "email.role_account", "email.free_provider", "email.typo", "email.domain_new", "email.domain", "email.domain_age_days", "ip.tor", "ip.hosting", "ip.vpn", "ip.proxy", "ip.relay", "ip.private", "ip.country", "ip.asn", "ip.hosting_provider", "captcha.passed", "duplicate.canonical_mailbox", "duplicate.device", "history.fraud", "login.new_country", "login.new_network", "content.spam", "content.phishing", "content.malware", "content.fraud", "checkout.amount", "checkout.currency", "checkout.card_country", "checkout.card_funding", "checkout.billing_country", "checkout.shipping_country", "device.automation", "device.timezone", "device.language", "score", "velocity.ip_1h", "velocity.ip_24h", "velocity.subnet_1h", "velocity.subnet_24h", "velocity.email_domain_1h", "velocity.email_domain_24h", "velocity.mailbox_1h", "velocity.mailbox_24h", "velocity.user_1h", "velocity.user_24h", "velocity.card_1h", "velocity.card_24h", "velocity.device_1h", "velocity.device_24h"): The signal to test, such as `email.disposable` or `ip.country`.
  - `operator` ("is" | "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "in" | "not_in", required): How to compare. Booleans use `is`, numbers `eq` to `lte`, and strings `eq`, `neq`, `in` and `not_in`.
  - `value` (boolean | number | string | string[], required, at most 320 characters, 1-100 items): What to compare it with: its type follows the field, and `in` and `not_in` take a list of strings.
- `action` ("allow" | "review" | "block"): `allow`: go ahead. `review`: suspicious; let it through with limits, or hold it for a person. `block`: refuse it.

## Example request

TypeScript (the `coss` package):

```ts
import { Coss } from "coss";

const coss = new Coss({
  apiKey: process.env.COSS_API_KEY,
  baseUrl: "https://api.coss.com",
});

const { data, error } = await coss.risk.rules.update("rskrule_01k7c8m4q2f3e9v6t5r1n0p8yz", {
  enabled: false,
});
```

HTTP:

```sh
curl -X PATCH "https://api.coss.com/v1/risk/rules/rskrule_01k7c8m4q2f3e9v6t5r1n0p8yz" \
  -H "Authorization: Bearer $COSS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "enabled": false
}'
```

Python:

```python
from coss import Coss

client = Coss()  # api_key= or COSS_API_KEY

client.risk.rules.update(
    id="rskrule_01k7c8m4q2f3e9v6t5r1n0p8yz",
    enabled=False,
)
```

Go:

```go
import (
	"context"

	coss "github.com/cosscom/coss-go"
	cossclient "github.com/cosscom/coss-go/client"
	risk "github.com/cosscom/coss-go/risk"
)

client := cossclient.NewClient() // option.WithAPIKey(…) or COSS_API_KEY

request := &risk.UpdateRiskRuleRequest{
    ID: "rskrule_01k7c8m4q2f3e9v6t5r1n0p8yz",
    Enabled: coss.Bool(
        false,
    ),
}
client.Risk.Rules.Update(
    context.TODO(),
    request,
)
```

Ruby:

```ruby
require "coss"

client = Coss::Client.new # api_key: or COSS_API_KEY

client.risk.rules.update(
  id: "rskrule_01k7c8m4q2f3e9v6t5r1n0p8yz",
  enabled: false
)
```

PHP:

```php
<?php

use Coss\Coss;
use Coss\Risk\Rules\Requests\UpdateRiskRuleRequest;

$client = new Coss(); // apiKey: or COSS_API_KEY

$client->risk->rules->update(
    'rskrule_01k7c8m4q2f3e9v6t5r1n0p8yz',
    new UpdateRiskRuleRequest([
        'enabled' => false,
    ]),
);
```

Java:

```java
import com.coss.Coss;
import com.coss.resources.risk.rules.requests.UpdateRiskRuleRequest;

Coss client = Coss.builder().build(); // .apiKey(…) or COSS_API_KEY

client.risk().rules().update(
    "rskrule_01k7c8m4q2f3e9v6t5r1n0p8yz",
    UpdateRiskRuleRequest
        .builder()
        .enabled(false)
        .build()
);
```

.NET:

```csharp
using Coss;
using Coss.Risk;

var client = new CossClient(); // apiKey: or COSS_API_KEY

await client.Risk.Rules.UpdateAsync(
    new UpdateRiskRuleRequest { Id = "rskrule_01k7c8m4q2f3e9v6t5r1n0p8yz", Enabled = false }
);
```

## Response 200

The rule, updated.

- `object` ("risk_rule", required)
- `id` (string, required)
- `name` (string, required): Your name for the rule, returned with reasons when it decides.
- `enabled` (boolean, required): `false`: it's kept, and no assessment applies it.
- `position` (integer, required): Rules are tried in ascending order.
- `events` (("signup" | "login" | "message" | "checkout" | "custom")[], required): Events it applies to; empty: every event.
- `match` ("all" | "any", required): `all`: every condition must hold. `any`: one is enough.
- `conditions` (object[], required): What must hold, by `match`.
  - `field` (string, required, one of "email.valid", "email.disposable", "email.undeliverable", "email.role_account", "email.free_provider", "email.typo", "email.domain_new", "email.domain", "email.domain_age_days", "ip.tor", "ip.hosting", "ip.vpn", "ip.proxy", "ip.relay", "ip.private", "ip.country", "ip.asn", "ip.hosting_provider", "captcha.passed", "duplicate.canonical_mailbox", "duplicate.device", "history.fraud", "login.new_country", "login.new_network", "content.spam", "content.phishing", "content.malware", "content.fraud", "checkout.amount", "checkout.currency", "checkout.card_country", "checkout.card_funding", "checkout.billing_country", "checkout.shipping_country", "device.automation", "device.timezone", "device.language", "score", "velocity.ip_1h", "velocity.ip_24h", "velocity.subnet_1h", "velocity.subnet_24h", "velocity.email_domain_1h", "velocity.email_domain_24h", "velocity.mailbox_1h", "velocity.mailbox_24h", "velocity.user_1h", "velocity.user_24h", "velocity.card_1h", "velocity.card_24h", "velocity.device_1h", "velocity.device_24h"): The signal to test, such as `email.disposable` or `ip.country`.
  - `operator` ("is" | "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "in" | "not_in", required): How to compare. Booleans use `is`, numbers `eq` to `lte`, and strings `eq`, `neq`, `in` and `not_in`.
  - `value` (boolean | number | string | string[], required, at most 320 characters, 1-100 items): What to compare it with: its type follows the field, and `in` and `not_in` take a list of strings.
- `action` ("allow" | "review" | "block", required): `allow`: go ahead. `review`: suspicious; let it through with limits, or hold it for a person. `block`: refuse it.
- `created_at` (string, required, date-time)
- `updated_at` (string, required, date-time)

Example:

```json
{
  "object": "risk_rule",
  "id": "rskrule_01k7c8m4q2f3e9v6t5r1n0p8yz",
  "name": "Disposable email from a data center",
  "enabled": true,
  "position": 0,
  "events": [
    "signup"
  ],
  "match": "all",
  "conditions": [
    {
      "field": "email.disposable",
      "operator": "is",
      "value": true
    },
    {
      "field": "ip.hosting",
      "operator": "is",
      "value": true
    }
  ],
  "action": "block",
  "created_at": "2026-01-15T09:30:00.000Z",
  "updated_at": "2026-01-15T09:30:00.000Z"
}
```

## Errors

- `400`: The body is not valid JSON (`invalid_json`). Also when the `Coss-Version` header names an unknown API version (`invalid_api_version`).
- `401`: The API key is missing, invalid, revoked or expired (`authentication_error`).
- `403`: The API key lacks the permission this endpoint needs (`permission_error`), or its organization is suspended (`organization_suspended`).
- `404`: No rule with this id exists in the API key's environment (`not_found`).
- `413`: The request body is larger than 5 MB (`payload_too_large`).
- `415`: The body is not sent as `application/json` (`unsupported_media_type`).
- `422`: The body failed validation (`validation_error`, see `issues`).
- `429`: Too many requests with this API key (`rate_limited`), or too many requests with invalid keys from this address (`too_many_failed_authentications`). Retry after `Retry-After` seconds. Successful responses carry `RateLimit-Limit`, `RateLimit-Remaining` and `RateLimit-Reset` (seconds until the limit is fully restored).
- `500`: Unexpected server error (`api_error` / `internal_error`).
- `503`: The API key could not be verified right now; retry (`service_unavailable`).