# Resource work hours

The work hours of a booking resource are the days of the week and the times when the resource accepts bookings. The methods in this subsection read a resource's work hours, set them as a whole, and remove them in a single call.

Bitrix24 API: `booking.v1.resource.slots.list`, `booking.v1.resource.slots.set`, `booking.v1.resource.slots.unset`
Scope: `booking`

## Operations

- [Get resource work hours](./slots-list.md) — `GET /v1/booking-resources/:id/slots`
- [Set resource work hours](./slots-set.md) — `PUT /v1/booking-resources/:id/slots`
- [Remove resource work hours](./slots-delete.md) — `DELETE /v1/booking-resources/:id/slots`

## Key fields

Work hours consist of intervals. The fields of one interval are returned in each `data.slots` element of the read response and passed in the write body. The resource ID for all three methods comes from the [`GET /v1/booking-resources`](/docs/entities/booking-resources/list) list.

| Field | Description |
|------|----------|
| `from` | Start of the interval in minutes from midnight: `600` is 10:00 |
| `to` | End of the interval in minutes from midnight, greater than `from` and no greater than `1440` |
| `weekDays` | Days of the week the interval applies to: `Mon`, `Tue`, `Wed`, `Thu`, `Fri`, `Sat`, `Sun` |
| `slotSize` | Length of one booking slot in minutes, at least `1` |
| `timezone` | Time zone in which `from` and `to` are set — a name from the IANA time zone database, for example `Europe/London` |
| `id` | Interval ID. Returned only in the read response and changes on every write |

## What to know before you start

1. **A write replaces all work hours.** [`PUT /v1/booking-resources/:id/slots`](./slots-set.md) deletes the previous intervals and recreates the supplied intervals with new `id` values. To add one interval, read the current ones, add the new one, and write the whole set. An empty `slots` array removes all work hours, just like [`DELETE /v1/booking-resources/:id/slots`](./slots-delete.md).
2. **A resource with work hours cannot be edited.** Editing a resource erases its work hours, so when work hours are set, [`PATCH /v1/booking-resources/:id`](/docs/entities/booking-resources/update) responds with `422 BOOKING_RESOURCE_SCHEDULE_CONFLICT` and does not change the resource. The order is: remove the work hours, change the resource, then set the work hours again. Do not set work hours in parallel with an edit: work hours written between the check and the edit itself are erased, and both requests succeed.
3. **An error in the values does not change the work hours.** A `slotSize` less than `1`, an offset instead of a time zone name, and a body without a `slots` array are rejected with `400 INVALID_PARAMS`. An error in the time range or the days of the week returns `422 BITRIX_ERROR`. In both cases the previous work hours remain.
4. **A read-only key reads work hours.** Write and remove requests with such a key return `403 WRITE_BLOCKED_READONLY_KEY`.

## Typical scenario

1. Find a resource: [`GET /v1/booking-resources`](/docs/entities/booking-resources/list) — or create one: [`POST /v1/booking-resources`](/docs/entities/booking-resources/create).
2. Read the current work hours: [`GET /v1/booking-resources/:id/slots`](./slots-list.md).
3. Write the whole set of intervals: [`PUT /v1/booking-resources/:id/slots`](./slots-set.md).
4. Before editing the resource, remove the work hours: [`DELETE /v1/booking-resources/:id/slots`](./slots-delete.md). Then change the resource: [`PATCH /v1/booking-resources/:id`](/docs/entities/booking-resources/update) — and write the work hours again.

## Limits

| Limit | Value |
|-------|----------|
| Request rate | 60 requests per minute per Bitrix24 account for each of the three methods; all API keys of the Bitrix24 account share one limit. The current limit is returned in the `x-ratelimit-limit` header |
| Read pagination | None: [`GET /v1/booking-resources/:id/slots`](./slots-list.md) returns all intervals of the resource in one call |
| Resources per call | One — the resource from the request path. Work hours of several resources are written in separate calls |

## See also

- [List booking resources](/docs/entities/booking-resources/list)
- [Get a booking resource](/docs/entities/booking-resources/get)
- [Update a booking resource](/docs/entities/booking-resources/update)
- [Booking resource types](/docs/entities/booking-resource-types)
- [Bookings](/docs/entities/bookings)
- [Limits and optimization](/docs/optimization)
