# rules.set

Save and activate filter rules.

Replaces the JSON filter rules for this mailbox, compiles them into a Sieve script, and activates them for incoming mail delivery.

```ts
openemail.rules.set(
  mailboxId: string,
  body: RulesDocument,
  options?: CallOptions,
): ApiPromise<FilterRulesPutResult>
```

It calls `PUT /mailboxes/{mailboxId}/rules`: [Save and activate filter rules](/docs/api/filtering/put_RulesPut) in the API reference.

## Example

```ts
const filterRulesPutResult = await openemail.rules.set(mailboxId, { rules: [{ conditions: [], actions: [] }] })
```

## Arguments

| Argument | Type | Description |
| --- | --- | --- |
| `mailboxId` | `string` | Mailbox ULID identifier. The path's `{mailboxId}`. |
| `body` | [`RulesDocument`](/docs/sdks/typescript/types/rules-document) | The request's body. |

## Options

It takes no options of its own. Every call also takes `signal`, `timeout`, `retry` and `headers`, which say how that one call is sent ([call options](/docs/sdks/typescript/calling-methods#call-options)).

## Answer

Awaited, it is the API's JSON, [`FilterRulesPutResult`](/docs/sdks/typescript/types/filter-rules-put-result). It is an [`ApiPromise`](/docs/sdks/typescript/responses): `.withResponse()` gives the same with the `Response` it came in, for its headers.

## Errors

| Status | What it means |
| --- | --- |
| `400` | validation_failed — malformed rules document; or destination_is_self / destination_loops / destination_chain_too_long when a redirect target routes back to this mailbox; or destination_unverified when a redirect target this save introduces has not been confirmed as a forwarding destination |
| `401` | unauthorized: the bearer credential is missing, malformed, expired, or revoked. Carries a `WWW-Authenticate: Bearer` challenge |
| `404` | Mailbox not found or not accessible to this principal |
| `409` | too_many_scripts; or mailbox_is_group_persona — a group persona's archive runs no rules |
| `413` | too_large — rules document exceeds size limit (48 KiB) |
| `422` | invalid_script — rules compile to an oversized or invalid Sieve script |
| `503` | temporary_failure: the mailbox or account is in transition while its store is being adopted; retry after Retry-After |

A failed call rejects with a [`RequestError`](/docs/sdks/typescript/errors): its `status`, and its `code`, the API's `error`. Decide on the code: one status covers several.

## Types

It names these types of the API, each on a page of its own: [`FilterRulesPutResult`](/docs/sdks/typescript/types/filter-rules-put-result), [`RulesDocument`](/docs/sdks/typescript/types/rules-document).
