# Update a rule

> **PUT** `https://api.us.nylas.com/v3/rules/{rule_id}`

Source: https://developer.nylas.com/docs/reference/api/rules/update-rule/

Updates the specified rule. All fields are optional — only provided fields are updated. The same validation rules
apply as on create.

**Authentication:** NYLAS_API_KEY

## Parameters

### Path parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `rule_id` | string | Yes | The ID of the rule to access. |

## Request body

Content-Type: application/json

- `name` (string)
- `description` (string)
- `priority` (integer)
- `enabled` (boolean)
- `trigger` (string) - The trigger the rule listens for. Inbound rules accept only `from.*` conditions. Outbound
rules accept `from.*`, `recipient.*`, and `outbound.type`.
- `match` (object)
  - `operator` (string) - Optional. When omitted, the rule defaults to `all`.
  - `conditions` (array)
    - `field` (string) - `from.*` fields match the normalized sender and are valid on both triggers.
`recipient.*` fields and `outbound.type` apply only to `outbound` rules.
`recipient.*` matches any recipient on the send, including To, CC, BCC, and SMTP
envelope recipients.
    - `operator` (string) - `outbound.type` accepts only `is` and `is_not`.
    - `value` (any) - For `in_list`, pass an array of List IDs. For `outbound.type`, pass `compose` or
`reply` (normalized to lowercase).
      - **string**
      - **array**
- `actions` (array)
  - `type` (string)
  - `value` (string)

## Responses

### 200 - OK

- `request_id` (string) - ID of the request.
- `data` (object)
  - `id` (string) - Globally unique identifier for the rule (UUID).
  - `name` (string) - A human-readable name for the rule. Required on create.
  - `description` (string) - An optional description of what the rule does.
  - `priority` (integer) - Execution order for the rule. Lower numbers run first. Must be between `0` and `1000`. Defaults to `10`.
  - `enabled` (boolean) - Whether the rule is active. Defaults to `true`.
  - `trigger` (string) - When the rule is evaluated. `inbound` rules run on incoming messages. `outbound` rules run on sends
before the message is submitted to the email provider — an `outbound` rule with a `block` action
rejects the send with HTTP 403 and no message is delivered. Non-blocking actions (`mark_as_spam`,
`archive`, `mark_as_read`, `mark_as_starred`, `assign_to_folder`, `trash`) on outbound rules apply
to the stored sent copy. Inbound and outbound rules are isolated: inbound rules never run during sends, and
outbound rules never run on receipt.
  - `match` (object) - Defines the conditions that must be met for the rule to apply.
    - `operator` (string) - How conditions are combined. Use `any` to match when any condition is true (OR), or `all` to
require every condition to be true (AND). When omitted, the rule defaults to `all`.
    - `conditions` (array) - The list of conditions to evaluate. At least one condition is required.
      - `field` (string) - The field to match against. `from.*` fields match the normalized sender and are valid on
both triggers: `from.address` is the full sender email, `from.domain` is the domain
portion, and `from.tld` is the top-level domain. `recipient.*` fields are valid only on
`outbound` rules and match against **any** recipient — including To, CC, BCC, and SMTP
envelope recipients. For `is_not`, the condition is true only when **no** recipient
matches. `outbound.type` is valid only on `outbound` rules and classifies the send as
`compose` (a fresh message) or `reply` (a reply to an existing thread). The type is
derived as `reply` when the send includes `reply_to_message_id` or the raw MIME
contains `In-Reply-To` or `References` headers; otherwise it's `compose`.
      - `operator` (string) - How to compare the field value. Use `is` for an exact match, `is_not` for the inverse,
`contains` for substring matching, or `in_list` to check against one or more List
resources. String matching is case-insensitive. The `outbound.type` field accepts only
`is` and `is_not` — `contains` and `in_list` are rejected.
      - `value` (any) - The value to compare the field against. For `is`, `is_not`, and `contains`, this is a
string. For `in_list`, this is an array of List IDs. For `outbound.type`, this is
`compose` or `reply` — values are normalized to lowercase on write.
        - **string**
        - **array**
  - `actions` (array) - The actions to perform when the rule matches. At least one action is required. The `block` action cannot be
combined with other actions — it is terminal.
    - `type` (string) - The action to take on the matching message or send. `block` rejects inbound mail at the SMTP
level or rejects an outbound send before provider submission. `mark_as_spam` routes the
message or stored sent copy to the spam folder, `assign_to_folder` moves it to the folder
specified in `value`, and the remaining actions modify the message state.
    - `value` (string) - Required when `type` is `assign_to_folder` — the target folder ID. Optional for other action types.
  - `application_id` (string) - The ID of the application that owns the rule. Read-only; derived from the authenticated API key.
  - `organization_id` (string) - The ID of the Nylas organization that owns the rule. Read-only; derived from the authenticated API key.
  - `created_at` (integer) - When the rule was created, in seconds using the Unix timestamp format.
  - `updated_at` (integer) - When the rule was last updated, in seconds using the Unix timestamp format.

### 400 - Bad Request

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.
  - `provider_error` (object) - The error from the provider.

### 401 - Unauthorized

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.
  - `provider_error` (object) - The error from the provider.

### 404 - Not Found

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.
  - `provider_error` (object) - The raw error from the provider, if available
    - `code` (string)
    - `message` (string)

### 429 - Rate Limit

- `request_id` (string) - The request ID.
- `error` (object) - The response error object.
  - `type` (string) - The error type.
  - `message` (string) - The error message.

## Code samples

### cURL

```bash
curl -X PUT "https://api.us.nylas.com/v3/rules/<RULE_ID>" \
  -H "Authorization: Bearer <NYLAS_API_KEY>" \
  -H "Content-Type: application/json" \
  -d '{
    "enabled": false
  }'

```

### Node.js SDK

```javascript
import Nylas from "nylas";

const nylas = new Nylas({
  apiKey: "<NYLAS_API_KEY>",
  apiUri: "<NYLAS_API_URI>",
});

async function updateRule() {
  try {
    const rule = await nylas.rules.update({
      ruleId: "<RULE_ID>",
      requestBody: {
        enabled: false,
        priority: 5,
      },
    });

    console.log("Updated rule:", rule);
  } catch (error) {
    console.error("Error updating rule:", error);
  }
}

updateRule();

```

### Python SDK

```python
from nylas import Client

nylas = Client(
    "<NYLAS_API_KEY>",
    "<NYLAS_API_URI>",
)

rule = nylas.rules.update(
    rule_id="<RULE_ID>",
    request_body={
        "enabled": False,
    },
)

print(rule)

```
