# PATCH /domains/{name}/mail/filters/{id}

First published 3 Oct 2026 (release 0.1.0) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the mail group.

Update a mail filter

- Who may call it: administrator, reseller, customer
- Token scope, any of: mail, all
- Answers: 200 OK

Supply at least one setting. Each supplied setting replaces its previous value. Supplying rules replaces the entire rule list. You can change match on its own. Use all to require every rule to match or any to require at least one match. If supplied, name must contain 1 to 64 printable ASCII characters. rules and action use the same formats and limits as POST /domains/{name}/mail/filters.

Use position to move the filter within its list. Positions start at 1, and position cannot exceed 100. A position past the end moves the filter to the end. The API returns 400 if no setting is supplied or a setting is invalid, and 404 if id does not identify a filter on the domain. UrbeStack compiles the updated filter with Pigeonhole and reports any compilation error. The 200 response contains the updated filter in filter.

Administrators, the domain's owner and the owner's reseller can call this operation with a token that has the mail scope.

## As a command

- [urbestack-mail-filter-set](https://urbestack.com/docs/commands/urbestack-mail-filter-set.md): Updates the mail filter selected by --id.

## Parameters

- `name` (path, DomainName, required)
- `id` (path, integer, required)

## Request body

JSON, the type [MailFilterPatch](https://urbestack.com/docs/api/types/MailFilterPatch.md).

- `action` (MailFilterAction)
- `match` (string, one of all, any)
- `name` (string, up to 64 characters)
- `position` (integer, 1 to 100)
- `rules` (array of MailFilterRule)

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
curl -sS -X PATCH "$API/domains/example.com/mail/filters/1" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "action": {
      "action": "folder",
      "target": "https://example.com/new"
    },
    "match": "all",
    "name": "alice",
    "position": 1,
    "rules": [
      {
        "field": "from",
        "op": "contains",
        "value": 8443
      }
    ]
  }'
```

Response, 200 OK:

```
{
  "filter": {
    "action": {
      "action": "folder",
      "target": "https://example.com/new"
    },
    "address": "info@example.com",
    "created_at": "2026-09-09T10:15:00Z",
    "domain": "example.com",
    "id": 1,
    "name": "alice",
    "position": 1,
    "rules": {}
  }
}
```

## Errors

- 400: --id is required
- 400: <what> must be a whole number from 0 to <max>
- 400: <what> must be text without control characters, 1 to <max> characters
- 400: A filter needs one to twenty rules
- 400: A rule is an object with field, op and value
- 400: A rule's field is one of from, to, subject, header, body
- 400: A rule's operator is one of contains, not-contains, equals, begins, ends, matches
- 400: Domain name required
- 400: Domain name too long
- 400: Invalid IPv4 address
- 400: Invalid IPv6 address
- 400: Invalid domain name
- 400: Invalid id
- 400: Invalid mail address
- 400: Invalid mail address: local part over 64 characters
- 400: Invalid mail address: no local part
- 400: Invalid mail address: the local part may hold letters, digits, dots, _ + and -
- 400: Invalid port
- 400: Invalid setting key
- 400: Nothing to change
- 400: The action is an object with action and, for folder and redirect, target
- 400: The action is folder, discard, redirect or stop
- 400: match is all or any
- 401: Authentication required
- 404: Filter <id> not found
- 404: No such filter: <id>
- 404: Setting '<key>' not found
