## Set resource work hours

`PUT /v1/booking-resources/:id/slots`

Sets the work hours of a booking resource to the passed set of intervals: the previous intervals are deleted. An empty `slots` array removes all work hours.

## Parameters

| Parameter | Type | Required | Description |
|----------|-----|:-----:|----------|
| `id` (path) | number | yes | Booking resource ID. List: [`GET /v1/booking-resources`](/docs/entities/booking-resources/list) |

## Request fields (body)

| Field | Type | Required | Description |
|------|-----|:-----:|----------|
| `slots` | array | yes | New set of work hour intervals. An empty array removes all work hours |
| `slots[].from` | number | yes | Start of the interval in minutes from midnight, at least `0`: `600` is 10:00 |
| `slots[].to` | number | yes | End of the interval in minutes from midnight, greater than `from` and no greater than `1440`: `1140` is 19:00 |
| `slots[].weekDays` | array | yes | Days of the week the interval applies to: `Mon`, `Tue`, `Wed`, `Thu`, `Fri`, `Sat`, `Sun`. At least one day is required |
| `slots[].slotSize` | number | yes | Length of one booking slot in minutes, at least `1`. The fractional part is discarded: `45.7` is stored as `45` |
| `slots[].timezone` | string | yes | Time zone in which `from` and `to` are set — a name from the IANA time zone database, for example `Europe/London`. An offset such as `+03:00` is not accepted |

The body accepts no other fields: any field alongside `slots` returns `400 INVALID_PARAMS`. An `id` field in an element, as returned when [reading the work hours](/docs/entities/booking-resources/slots-list), is ignored: after the write, the intervals get new `id` values.

## Examples

### curl — personal key

```bash
curl -X PUT "https://vibecode.bitrix24.com/v1/booking-resources/65/slots" \
  -H "X-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "slots": [
      { "from": 600, "to": 1140, "weekDays": ["Mon", "Tue", "Wed", "Thu", "Fri"], "slotSize": 30, "timezone": "Europe/London" },
      { "from": 600, "to": 840, "weekDays": ["Sat"], "slotSize": 60, "timezone": "Europe/London" }
    ]
  }'
```

### curl — OAuth application

```bash
curl -X PUT "https://vibecode.bitrix24.com/v1/booking-resources/65/slots" \
  -H "X-Api-Key: YOUR_APP_KEY" \
  -H "Authorization: Bearer USER_SESSION_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "slots": [
      { "from": 600, "to": 1140, "weekDays": ["Mon", "Tue", "Wed", "Thu", "Fri"], "slotSize": 30, "timezone": "Europe/London" },
      { "from": 600, "to": 840, "weekDays": ["Sat"], "slotSize": 60, "timezone": "Europe/London" }
    ]
  }'
```

### JavaScript — personal key

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/booking-resources/65/slots', {
  method: 'PUT',
  headers: {
    'X-Api-Key': 'YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    slots: [
      { from: 600, to: 1140, weekDays: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'], slotSize: 30, timezone: 'Europe/London' },
      { from: 600, to: 840, weekDays: ['Sat'], slotSize: 60, timezone: 'Europe/London' },
    ],
  }),
})

const { success, data } = await res.json()
console.log('Work hours set:', data)
```

### JavaScript — OAuth application

```javascript
const res = await fetch('https://vibecode.bitrix24.com/v1/booking-resources/65/slots', {
  method: 'PUT',
  headers: {
    'X-Api-Key': 'YOUR_APP_KEY',
    'Authorization': 'Bearer USER_SESSION_TOKEN',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    slots: [
      { from: 600, to: 1140, weekDays: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'], slotSize: 30, timezone: 'Europe/London' },
      { from: 600, to: 840, weekDays: ['Sat'], slotSize: 60, timezone: 'Europe/London' },
    ],
  }),
})

const { success, data } = await res.json()
```

## Response fields

The written intervals are not included in the response — [`GET /v1/booking-resources/:id/slots`](/docs/entities/booking-resources/slots-list) returns them.

| Field | Type | Description |
|------|-----|----------|
| `success` | boolean | `true` on success |
| `data` | boolean | `true` — the work hours are written |

## Response example

```json
{
  "success": true,
  "data": true
}
```

## Error response example

422 — the time range or the days of the week are set incorrectly:

```json
{
  "success": false,
  "error": {
    "code": "BITRIX_ERROR",
    "message": "Invalid range fields",
    "b24Code": "422"
  }
}
```

## Errors

| HTTP | Code | Description |
|------|-----|----------|
| 422 | `BITRIX_ERROR` | `Invalid range fields` — `to` is not greater than `from`, a time is outside the range from `0` to `1440`, the `weekDays` array is empty or contains an unknown day. The work hours do not change |
| 422 | `BITRIX_ERROR` | `Required fields: from` — the element has no `from`. For `to` and `weekDays`, the message names that field |
| 400 | `INVALID_PARAMS` | `Provide slots as an array of objects` — the body has no `slots`, `slots` is not an array, an array element is not an object, or another field is passed alongside `slots` |
| 400 | `INVALID_PARAMS` | `slotSize must be positive` — the element has no `slotSize` or it is less than `1` |
| 400 | `INVALID_PARAMS` | `slotSize must be a positive decimal number` — `slotSize` is passed as a string that is not a number |
| 400 | `INVALID_PARAMS` | `timezone must be an IANA time zone` — the element has no `timezone`, it holds an offset such as `+03:00`, or the IANA time zone database has no such name |
| 400 | `INVALID_PARAMS` | `id must be a positive safe integer` — the resource `id` is not a positive integer |
| 404 | `ENTITY_NOT_FOUND` | `Booking resource not found` — no resource with this `id` exists |
| 401 | `MISSING_API_KEY` | The `X-Api-Key` header is not passed |
| 401 | `TOKEN_MISSING` | The key has no Bitrix24 tokens |
| 403 | `WRITE_BLOCKED_READONLY_KEY` | The key is in read-only mode. The request is rejected before it reaches Bitrix24 |
| 403 | `SCOPE_DENIED` | The key does not have the `booking` scope |
| 429 | `RATE_LIMITED` | Request rate exceeded. The effective cap is in the `x-ratelimit-limit` header |
| 502 | `BITRIX_RESPONSE_INVALID` | `Bitrix24 returned an invalid booking response` — Bitrix24 did not confirm the write |

Full list of common API errors — [Errors](/docs/errors).

## Known specifics

**Do not set work hours in parallel with a resource edit.** 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`. If work hours are written in the gap between this check and the edit itself, the edit erases them, and both requests respond with success. After editing a resource, verify the work hours via [`GET /v1/booking-resources/:id/slots`](/docs/entities/booking-resources/slots-list).

## See also

- [Resource work hours](/docs/entities/booking-resources/slots)
- [Get resource work hours](/docs/entities/booking-resources/slots-list)
- [Remove resource work hours](/docs/entities/booking-resources/slots-delete)
- [Update a booking resource](/docs/entities/booking-resources/update)
- [List booking resources](/docs/entities/booking-resources/list)
