> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getnexor.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Replace routing rules

> Replace an agent's routing rules in one call. Array order is priority. Requires confirm: true.

This call replaces the whole list. To add, edit, or reorder a single rule, read the list with [List rules](/docs/en/api/inbound-router/list-routing-rules), change it, and send it back complete.

* Array order is priority: the first rule is checked first.
* `rules: []` removes every rule.
* Every saved rule gets a new `id`.
* If one rule is invalid, nothing is saved.
* `target_workflow_id` must be one of the agent's tasks, otherwise 400 `invalid_rule_target_workflow`.

```json theme={null}
{
  "rules": [
    {
      "name": "Existing customers",
      "conditions": [
        { "field": "first_message_text", "operator": "regex", "value": "(my order|tracking|refund)" }
      ],
      "target_workflow_id": "33333333-3333-4333-8333-333333333333"
    },
    {
      "name": "Web chat from Chile",
      "conditions": [
        { "field": "channel", "operator": "eq", "value": "webchat" },
        { "field": "metadata.country", "operator": "eq", "value": "CL" }
      ],
      "target_workflow_id": "22222222-2222-4222-8222-222222222222"
    }
  ],
  "confirm": true
}
```

## Conditions

All conditions of a rule must match. A rule without conditions matches every conversation, so put it last.

| `field` | What it checks |
| - | - |
| `channel` | Channel of the conversation, such as `whatsapp`, `webchat`, or `email`. |
| `first_message_text` | The lead's first message. |
| `source` | Where the lead came from, as saved on the lead. |
| `phone`, `email` | The lead's phone number and email. |
| `tags` | The lead's tags. |
| `metadata.country` | Any value in the lead's metadata, written as a dotted path. |

| `operator` | Matches when the value |
| - | - |
| `eq`, `neq` | is equal, or different. |
| `gt`, `gte`, `lt`, `lte` | is greater or less than a number. |
| `contains`, `not_contains` | contains a piece of text, or does not. |
| `in`, `not_in` | is one of the values of an array, or none of them. |
| `regex` | matches a regular expression. |
| `exists`, `not_exists` | has a value, or has none. These two do not use `value`. |

Text comparisons ignore upper and lower case. Before going live, check the order with [Test a message](/docs/en/api/inbound-router/test-inbound-router).


## API Specification

The full API specification for this endpoint is available in the [documentation index](https://docs.getnexor.ai/llms.txt).
