# mv.inboundRoutes

> The inboundRoutes methods of @morevoice/sdk: How inbound calls to your numbers are routed.

How inbound calls to your numbers are routed. These methods are on `mv.inboundRoutes`, where `mv` is your client (see [the Node.js SDK](https://docs.morevoice.ai/sdk/node/#connect)). Each one returns the response object and throws when the API answers with an error.

## `create()`

**Create an inbound route.** Adds a rule that answers inbound calls. `target` is required: an assistant, a published flow, a queue, a person or a conference room. The other fields default: enabled, priority 100, any connection, any dialled number and any caller. `match_did` and `match_caller` take an exact number, a prefix ending in `*`, or nothing for any. The next call uses the new rule.

```ts
mv.inboundRoutes.create(body?: InboundRoutesCreateData["body"], options?: RequestOptions): Promise<InboundRoutesCreateResponse>
```

`POST /inbound_routes` · [API reference](https://docs.morevoice.ai/api/operations/inbound_routes_create/)

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `body.assistant_request_timeout_ms` | `integer` | no | 200–5000 ms (default 1500): after this, the route's own target answers. |
| `body.assistant_request_url` | `string \| null` | no | A public https URL asked which assistant answers each matching call (see the assistant-request guide); null turns it off. |
| `body.connection_id` | `string \| null` | no | `conn_…` ID. |
| `body.enabled` | `boolean` | no |  |
| `body.fallback_assistant_id` | `string \| null` | no | `asst_…` ID. |
| `body.match_caller` | `string` | no | The caller's number: exact, a prefix ending in `*`, or empty for any. |
| `body.match_did` | `string` | no | The dialled number: exact, a prefix ending in `*`, or empty for any. |
| `body.name` | `string` | no |  |
| `body.priority` | `integer` | no |  |
| `body.stream` | `RouteStreamParamsInput \| null` | no | Your own bot answers the route's calls over a media stream (connect mode), instead of a `target`; null removes it. Needs media streams on your plan. |
| `body.target` | `RouteTargetParamsInput` | no | Where a matching call goes: `type`, and the ID in `<type>_id`. |
| `options.headers["MoreVoice-Version"]` | `string` | no | The API version to use for this request. Defaults to the version the API key is pinned to. |
| `options.headers["Idempotency-Key"]` | `string` | no | A unique key (for example a UUID) that makes this request safe to retry: for 24 hours, a retry with the same key and parameters returns the first response instead of acting twice. |
| `options` | `RequestOptions` | no | `idempotencyKey`, extra `headers` and an abort `signal`: see [retries and idempotency](https://docs.morevoice.ai/sdk/typescript/retries/). |

### Returns

`InboundRoute`:

| Field | Type | Description |
| --- | --- | --- |
| `id` | `string` | The route's ID. |
| `object` | `"inbound_route"` | Always `inbound_route`. |
| `livemode` | `boolean` | `true` in live mode, `false` in test mode. |
| `name` | `string` | — |
| `enabled` | `boolean` | — |
| `priority` | `integer` | Lower runs first; the first matching route wins. |
| `connection_id` | `string \| null` | `conn_…` ID. |
| `match_did` | `string` | The dialled number: exact, a prefix ending in `*`, or empty for any. |
| `match_caller` | `string` | The caller's number: exact, a prefix ending in `*`, or empty for any. |
| `target` | `RouteTarget \| null` | Where matching calls go (null: the connection's inbound assistant answers). |
| `fallback_assistant_id` | `string \| null` | `asst_…` ID. |
| `assistant_request_url` | `string \| null` | When set, this URL is asked (a signed POST, `assistant.request`) which assistant, flow or queue answers each matching call, and with which variables; the route's own target answers when it does not reply in time. Null: off. |
| `assistant_request_timeout_ms` | `integer` | How long the assistant request may take (200–5000 ms) before the route's own target answers. |
| `stream` | `RouteStream \| null` | When set, your own bot answers the route's calls over a media stream (connect mode) and `target` is null; `fallback_assistant_id` takes the calls your bot can't (unreachable, or it drops). Null: off. |
| `created` | `string` | An ISO-8601 timestamp in UTC. |

### Example

```ts
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // MOREVOICE_API_KEY from the environment

const inboundRoute = await mv.inboundRoutes.create({
	fallback_assistant_id: "asst_3cYbE6uYvGkH8w4ZK1rTqd",
	match_did: "+97231234567",
	name: "Sales line",
	target: {
		queue_id: "q_4Gk2LmN9pQ4rS6tV8wX0yZ",
		type: "queue",
	},
});
console.log(inboundRoute);
```

## `delete()`

**Delete an inbound route.** Deletes an inbound route. Calls already in progress are not affected; the next call is routed by the remaining rules.

```ts
mv.inboundRoutes.delete(id: InboundRoutesDeleteData["path"]["id"], options?: RequestOptions): Promise<InboundRoutesDeleteResponse>
```

`DELETE /inbound_routes/{id}` · [API reference](https://docs.morevoice.ai/api/operations/inbound_routes_delete/)

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | yes | A inbound route ID (`rte_…`). |
| `options.headers["MoreVoice-Version"]` | `string` | no | The API version to use for this request. Defaults to the version the API key is pinned to. |
| `options.headers["Idempotency-Key"]` | `string` | no | A unique key (for example a UUID) that makes this request safe to retry: for 24 hours, a retry with the same key and parameters returns the first response instead of acting twice. |
| `options` | `RequestOptions` | no | `idempotencyKey`, extra `headers` and an abort `signal`: see [retries and idempotency](https://docs.morevoice.ai/sdk/typescript/retries/). |

### Returns

`DeletedInboundRoute`:

| Field | Type | Description |
| --- | --- | --- |
| `id` | `string` | A inbound route ID (prefix `rte_`). |
| `object` | `"inbound_route"` | Always `inbound_route`. |
| `deleted` | `true` | — |

### Example

```ts
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // MOREVOICE_API_KEY from the environment

const deletedInboundRoute = await mv.inboundRoutes.delete("rte_7Hk2Lm9Qp");
console.log(deletedInboundRoute);
```

## `list()`

**List inbound routes.** Your routes in evaluation order: priority, then age. The first enabled route that matches a call wins.

```ts
mv.inboundRoutes.list(query?: NonNullable<InboundRoutesListData["query"]>, options?: RequestOptions): PagedList<InboundRoutesListResponse["data"][number], NonNullable<InboundRoutesListData["query"]>>
```

`GET /inbound_routes` · [API reference](https://docs.morevoice.ai/api/operations/inbound_routes_list/)

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `query.limit` | `integer` | no | How many objects to return, 1–100 (default 20). |
| `query.starting_after` | `string` | no | A cursor (`next_cursor`) or object ID: return the objects after it (older). |
| `query.ending_before` | `string` | no | A cursor or object ID: return the objects before it (newer). |
| `options.headers["MoreVoice-Version"]` | `string` | no | The API version to use for this request. Defaults to the version the API key is pinned to. |
| `options` | `RequestOptions` | no | `idempotencyKey`, extra `headers` and an abort `signal`: see [retries and idempotency](https://docs.morevoice.ai/sdk/typescript/retries/). |

### Returns

A [`PagedList`](https://docs.morevoice.ai/sdk/typescript/pagination/): `await` it for the first page, `for await` it for every item.

### Example

```ts
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // MOREVOICE_API_KEY from the environment

for await (const inboundRoute of mv.inboundRoutes.list()) {
	console.log(inboundRoute);
}
```

## `retrieve()`

**Retrieve an inbound route.** Returns an inbound route: what it matches (`connection_id`, `match_did`, `match_caller`), its `priority`, whether it is `enabled`, and its `target`.

```ts
mv.inboundRoutes.retrieve(id: InboundRoutesRetrieveData["path"]["id"], options?: RequestOptions): Promise<InboundRoutesRetrieveResponse>
```

`GET /inbound_routes/{id}` · [API reference](https://docs.morevoice.ai/api/operations/inbound_routes_retrieve/)

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | yes | A inbound route ID (`rte_…`). |
| `options.headers["MoreVoice-Version"]` | `string` | no | The API version to use for this request. Defaults to the version the API key is pinned to. |
| `options` | `RequestOptions` | no | `idempotencyKey`, extra `headers` and an abort `signal`: see [retries and idempotency](https://docs.morevoice.ai/sdk/typescript/retries/). |

### Returns

`InboundRoute`:

| Field | Type | Description |
| --- | --- | --- |
| `id` | `string` | The route's ID. |
| `object` | `"inbound_route"` | Always `inbound_route`. |
| `livemode` | `boolean` | `true` in live mode, `false` in test mode. |
| `name` | `string` | — |
| `enabled` | `boolean` | — |
| `priority` | `integer` | Lower runs first; the first matching route wins. |
| `connection_id` | `string \| null` | `conn_…` ID. |
| `match_did` | `string` | The dialled number: exact, a prefix ending in `*`, or empty for any. |
| `match_caller` | `string` | The caller's number: exact, a prefix ending in `*`, or empty for any. |
| `target` | `RouteTarget \| null` | Where matching calls go (null: the connection's inbound assistant answers). |
| `fallback_assistant_id` | `string \| null` | `asst_…` ID. |
| `assistant_request_url` | `string \| null` | When set, this URL is asked (a signed POST, `assistant.request`) which assistant, flow or queue answers each matching call, and with which variables; the route's own target answers when it does not reply in time. Null: off. |
| `assistant_request_timeout_ms` | `integer` | How long the assistant request may take (200–5000 ms) before the route's own target answers. |
| `stream` | `RouteStream \| null` | When set, your own bot answers the route's calls over a media stream (connect mode) and `target` is null; `fallback_assistant_id` takes the calls your bot can't (unreachable, or it drops). Null: off. |
| `created` | `string` | An ISO-8601 timestamp in UTC. |

### Example

```ts
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // MOREVOICE_API_KEY from the environment

const inboundRoute = await mv.inboundRoutes.retrieve("rte_7Hk2Lm9Qp");
console.log(inboundRoute);
```

## `update()`

**Update an inbound route.** Changes the fields you send. A new `target` replaces the old one (and drops `fallback_assistant_id` when the new target is an assistant).

```ts
mv.inboundRoutes.update(id: InboundRoutesUpdateData["path"]["id"], body?: InboundRoutesUpdateData["body"], options?: RequestOptions): Promise<InboundRoutesUpdateResponse>
```

`PATCH /inbound_routes/{id}` · [API reference](https://docs.morevoice.ai/api/operations/inbound_routes_update/)

### Parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | yes | A inbound route ID (`rte_…`). |
| `body.assistant_request_timeout_ms` | `integer` | no | 200–5000 ms (default 1500): after this, the route's own target answers. |
| `body.assistant_request_url` | `string \| null` | no | A public https URL asked which assistant answers each matching call (see the assistant-request guide); null turns it off. |
| `body.connection_id` | `string \| null` | no | `conn_…` ID. |
| `body.enabled` | `boolean` | no |  |
| `body.fallback_assistant_id` | `string \| null` | no | `asst_…` ID. |
| `body.match_caller` | `string` | no | The caller's number: exact, a prefix ending in `*`, or empty for any. |
| `body.match_did` | `string` | no | The dialled number: exact, a prefix ending in `*`, or empty for any. |
| `body.name` | `string` | no |  |
| `body.priority` | `integer` | no |  |
| `body.stream` | `RouteStreamParamsInput \| null` | no | Your own bot answers the route's calls over a media stream (connect mode), instead of a `target`; null removes it. Needs media streams on your plan. |
| `body.target` | `RouteTargetParamsInput` | no | Where a matching call goes: `type`, and the ID in `<type>_id`. |
| `options.headers["MoreVoice-Version"]` | `string` | no | The API version to use for this request. Defaults to the version the API key is pinned to. |
| `options` | `RequestOptions` | no | `idempotencyKey`, extra `headers` and an abort `signal`: see [retries and idempotency](https://docs.morevoice.ai/sdk/typescript/retries/). |

### Returns

`InboundRoute`:

| Field | Type | Description |
| --- | --- | --- |
| `id` | `string` | The route's ID. |
| `object` | `"inbound_route"` | Always `inbound_route`. |
| `livemode` | `boolean` | `true` in live mode, `false` in test mode. |
| `name` | `string` | — |
| `enabled` | `boolean` | — |
| `priority` | `integer` | Lower runs first; the first matching route wins. |
| `connection_id` | `string \| null` | `conn_…` ID. |
| `match_did` | `string` | The dialled number: exact, a prefix ending in `*`, or empty for any. |
| `match_caller` | `string` | The caller's number: exact, a prefix ending in `*`, or empty for any. |
| `target` | `RouteTarget \| null` | Where matching calls go (null: the connection's inbound assistant answers). |
| `fallback_assistant_id` | `string \| null` | `asst_…` ID. |
| `assistant_request_url` | `string \| null` | When set, this URL is asked (a signed POST, `assistant.request`) which assistant, flow or queue answers each matching call, and with which variables; the route's own target answers when it does not reply in time. Null: off. |
| `assistant_request_timeout_ms` | `integer` | How long the assistant request may take (200–5000 ms) before the route's own target answers. |
| `stream` | `RouteStream \| null` | When set, your own bot answers the route's calls over a media stream (connect mode) and `target` is null; `fallback_assistant_id` takes the calls your bot can't (unreachable, or it drops). Null: off. |
| `created` | `string` | An ISO-8601 timestamp in UTC. |

### Example

```ts
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // MOREVOICE_API_KEY from the environment

const inboundRoute = await mv.inboundRoutes.update("rte_7Hk2Lm9Qp", {
	enabled: false,
});
console.log(inboundRoute);
```
