# sieve.putScript

Upload or replace a Sieve filter script.

Uploads or updates a Sieve script. The script is validated for syntax before saving. Returns error 422 if compilation fails.

```ts
openemail.sieve.putScript(
  mailboxId: string,
  scriptName: string,
  body: SievePutScriptBody,
  options?: SievePutScriptOptions,
): ApiPromise<SievePutResult>
```

It calls `PUT /mailboxes/{mailboxId}/sieve/scripts/{scriptName}`: [Upload or replace a Sieve filter script](/docs/api/filtering/put_SievePut) in the API reference.

## Example

```ts
const sievePutResult = await openemail.sieve.putScript(mailboxId, scriptName, { script: '…' })
```

## Arguments

| Argument | Type | Description |
| --- | --- | --- |
| `mailboxId` | `string` | Mailbox ULID identifier. The path's `{mailboxId}`. |
| `scriptName` | `string` | Sieve script name. The path's `{scriptName}`. |
| `body` | [`SievePutScriptBody`](#sieveputscriptbody) | The request's body. |

## Options

The last argument, `options`, a `SievePutScriptOptions`, takes:

| Option | Type | Sent as | Description |
| --- | --- | --- | --- |
| `ifNoneMatch` | `string` | header `if-none-match` | Set to "*" for create-only: prevents overwriting an existing script of the same name |

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, [`SievePutResult`](/docs/sdks/typescript/types/sieve-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 name or body; 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 write 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 |
| `403` | reserved — this script name is reserved for JSON rules |
| `404` | Mailbox not found or not accessible to this principal |
| `409` | too_many_scripts, name_exists, or mailbox_is_group_persona (a group persona's archive runs no script) |
| `413` | too_large: JSON request body exceeds 1 MiB or 500,000 values (object keys included), checked before parsing |
| `422` | invalid_script — Sieve syntax error with line and column |
| `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

### SievePutScriptBody

```ts
/** The body of `sieve.putScript`. */
type SievePutScriptBody = {
  /** Sieve script source code */
  script: string
}
```

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