# Restrictions

An explanation of the algorithms used to support [Set restrictions](/connector-api/operations/restrictions.md#set-restrictions) and [Clear restrictions](/connector-api/operations/restrictions.md#clear-restrictions).

## What are restrictions?

Restrictions give **Mews** customers more control over their reservations, by preventing guests from making bookings that meet certain conditions. Restrictions can be applied to rates and space types, to control the way guests can book them. For example:

* Use restrictions to implement a promotional rate which applies only to weekend bookings during July and August
* Use restrictions to prevent guests from booking a room in a particular space type category (room type)

{% hint style="info" %}

#### Additional help on restrictions

* [Understanding restrictions in Mews Operations](https://help.mews.com/s/article/Understanding-restrictions-in-Mews-Operations?language=en_US)
* [How to create restrictions in Mews Operations](https://help.mews.com/s/article/How-to-create-restrictions-in-Mews-Operations?language=en_US)
* [Search all Help articles related to restrictions](https://help.mews.com/s/global-search/restrictions?language=en_US)
  {% endhint %}

## Restrictions in the API

To retrieve information about restrictions, use [Get all restrictions](/connector-api/operations/restrictions.md#get-all-restrictions). To add and remove restrictions, use [Set restrictions](/connector-api/operations/restrictions.md#set-restrictions) and [Clear restrictions](/connector-api/operations/restrictions.md#clear-restrictions) respectively.

| 'How to' use case                  | API Operations                                                                         |
| ---------------------------------- | -------------------------------------------------------------------------------------- |
| How to get service restrictions    | [Get all restrictions](/connector-api/operations/restrictions.md#get-all-restrictions) |
| How to add service restrictions    | [Set restrictions](/connector-api/operations/restrictions.md#set-restrictions)         |
| How to remove service restrictions | [Clear restrictions](/connector-api/operations/restrictions.md#clear-restrictions)     |

{% hint style="warning" %}

#### Restrictions are independent of user and API restrictions

As an API user you can only set and clear your own restrictions, independently of restrictions set within the user interface of **Mews Operations**.. See [Scope of restrictions](#scope-of-restrictions) for more details.
{% endhint %}

## Restrictions quota limit

Each service can have up to 150,000 active restrictions at any given time. This includes restrictions created both through the API and through the user interface of **Mews Operations**. In practice, the risk of hitting this quota is low because [Set restrictions](/connector-api/operations/restrictions.md#set-restrictions) merges multiple similar restrictions into a single restriction. Its sibling operation [Clear restrictions](/connector-api/operations/restrictions.md#clear-restrictions) uses a splicing algorithm to work out how to divide up any existing restrictions to meet the specified time interval.

The following sections explain the algorithms used by these operations in more detail.

## Merging algorithm

When using [Set restrictions](/connector-api/operations/restrictions.md#set-restrictions), if a specified restriction already exists with the same conditions, or if multiple specified restrictions match in all properties but differ in time interval and follow each other chronologically, a merging algorithm is applied to combine them. This reduces the overall number of restrictions and improves system performance. The merging algorithm is as follows:

* If the exceptions of the new restriction match the old restriction:
  * If the new interval is longer than the old one, a new restriction is created joining the two intervals.
  * If the new interval is shorter, no changes are made.
* If the exceptions of the new restriction do *not* match the old restriction:
  * If the new interval overlaps the old interval, the old restriction will be [spliced](#time-interval-splicing) before and after the new interval. Restrictions matching the old restriction are then added at the appropriate interval along with the new restriction.
  * If the new interval does *not* overlap the old interval, the new restriction is added as usual.

## Matching conditions

The conditions specified in [Set restrictions](/connector-api/operations/restrictions.md#set-restrictions) and [Clear restrictions](/connector-api/operations/restrictions.md#clear-restrictions) must be met exactly. For example:

> A bookable service has two restrictions A and B. Restriction A applies to resource category C1 and rate R1. Restriction B applies to resource category C1 and to all rates. If [Clear restrictions](/connector-api/operations/restrictions.md#clear-restrictions) is called, specifying a restriction condition of resource category C1 but with no rate specified (this defaults to *all* rates), then only Restriction B is cleared, not Restriction A.

## Time interval splicing

The time interval for a specified restriction does not need to correspond to an existing restriction in the system, instead the API uses a splicing algorithm to work out how to divide up any existing restrictions to meet the specified time interval. For example:

> An existing restriction in the system A applies from 5th January to 25th January. As usual, time intervals are inclusive, meaning that the time interval includes both the 5th January and the 25th January. If the [Clear restrictions](/connector-api/operations/restrictions.md#clear-restrictions) operation is called, specifying a restriction time interval of 10th January to 20th January, i.e. within the original restriction A, then the time interval of restriction A is split into three separate intervals. The original restriction A is deleted, and in its place new restriction B is created for the period of time from 5th January to 9th January inclusive, and new restriction C is created for the period of time from 21st January to 25th January. Thus the period 10th January to 20th January has been cleared, but without affecting other time periods.

## Scope of restrictions

Only restrictions created through the API are affected by these operations, *not* restrictions created by the user within **Mews Operations**. Similarly, if a user creates a restriction in **Mews Operations**, this will *not* affect restrictions created through the API. User restrictions and API restrictions are independent.

{% hint style="danger" %}

#### Single third-party integration per enterprise

We assume that only one third-party integration manages restrictions for a given enterprise or property. All restrictions set up in an enterprise are created either by the enterprise itself through the **Mews Operations** user interface, or uniquely by a single integration through the API. These two sources can be identified using the `Origin` field in requests and responses to [Get all restrictions](/connector-api/operations/restrictions.md#get-all-restrictions).
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mews.com/connector-api/concepts/restrictions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
