Get Resource Bookings by Filter calendar.resource.booking.list

Scope: calendar

Who can execute the method: any user

This method retrieves resource bookings based on a filter.

Method Parameters

Required parameters are marked with *

Name
type

Description

filter*
object

Filter fields

Filter Parameter

Required parameters are marked with *

Name
type

Description

resourceTypeIdList*
array

List of resource identifiers.

Identifiers can be obtained using the method calendar.resource.list

from
date

Start date of the period

to
date

End date of the period

resourceIdList*
array

List of resource booking identifiers from the custom field of type resourcebooking in leads or deals in CRM.

Identifiers can be obtained via:

To find out which custom fields have the type resourcebooking, you can use the method crm.lead.userfield.list for leads and the method crm.deal.userfield.list for deals

In the method calendar.resource.booking.list, you must use only one of the two required parameters: resourceTypeIdList or resourceIdList. Both parameters cannot be used together.

Code Examples

Example 1. Assess resource availability over a period, for instance, to create custom views of availability or for use in application logic.

How to Use Examples in Documentation

curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"filter":{"resourceTypeIdList":[10852,10888,10873,10871,10853],"from":"2024-06-20","to":"2024-08-20"}}' \
        https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/calendar.resource.booking.list
        
curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"filter":{"resourceTypeIdList":[10852,10888,10873,10871,10853],"from":"2024-06-20","to":"2024-08-20"},"auth":"**put_access_token_here**"}' \
        https://**put_your_bitrix24_address**/rest/calendar.resource.booking.list
        
// callListMethod: Retrieves all data at once. Use only for small selections (< 1000 items) due to high memory usage.
        
        try {
          const response = await $b24.callListMethod(
            'calendar.resource.booking.list',
            {
              filter: {
                resourceTypeIdList: [10852, 10888, 10873, 10871, 10853],
                from: '2024-06-20',
                to: '2024-08-20',
              }
            },
            (progress) => { console.log('Progress:', progress) }
          );
          const items = response.getData() || [];
          for (const entity of items) { console.log('Entity:', entity); }
        } catch (error) {
          console.error('Request failed', error);
        }
        
        // fetchListMethod: Retrieves data in parts using an iterator. Use it for large data volumes to optimize memory usage.
        
        try {
          const generator = $b24.fetchListMethod('calendar.resource.booking.list', {
            filter: {
              resourceTypeIdList: [10852, 10888, 10873, 10871, 10853],
              from: '2024-06-20',
              to: '2024-08-20',
            }
          }, 'ID');
          for await (const page of generator) {
            for (const entity of page) { console.log('Entity:', entity); }
          }
        } catch (error) {
          console.error('Request failed', error);
        }
        
        // callMethod: Manually controls pagination through the start parameter. Use it for precise control of request batches. For large datasets, it is less efficient than fetchListMethod.
        
        try {
          const response = await $b24.callMethod('calendar.resource.booking.list', {
            filter: {
              resourceTypeIdList: [10852, 10888, 10873, 10871, 10853],
              from: '2024-06-20',
              to: '2024-08-20',
            }
          }, 0);
          const result = response.getData().result || [];
          for (const entity of result) { console.log('Entity:', entity); }
        } catch (error) {
          console.error('Request failed', error);
        }
        
try {
            $response = $b24Service
                ->core
                ->call(
                    'calendar.resource.booking.list',
                    [
                        'filter' => [
                            'resourceTypeIdList' => [10852, 10888, 10873, 10871, 10853],
                            'from'              => '2024-06-20',
                            'to'                => '2024-08-20',
                        ],
                    ]
                );
        
            $result = $response
                ->getResponseData()
                ->getResult();
        
            echo 'Success: ' . print_r($result, true);
            // Your logic for processing data
            processData($result);
        
        } catch (Throwable $e) {
            error_log($e->getMessage());
            echo 'Error fetching resource booking list: ' . $e->getMessage();
        }
        
BX24.callMethod(
            'calendar.resource.booking.list',
            {
                filter: {
                    resourceTypeIdList: [10852, 10888, 10873, 10871, 10853],
                    from: '2024-06-20',
                    to: '2024-08-20',
                }
            }
        );
        
require_once('crest.php');
        
        $result = CRest::call(
            'calendar.resource.booking.list',
            [
                'filter' => [
                    'resourceTypeIdList' => [10852, 10888, 10873, 10871, 10853],
                    'from' => '2024-06-20',
                    'to' => '2024-08-20'
                ]
            ]
        );
        
        echo '<PRE>';
        print_r($result);
        echo '</PRE>';
        

Example 2. Select bookings by their identifiers from custom fields of the CRM entity.

How to Use Examples in Documentation

curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"filter":{"resourceIdList":[10,18,17]}}' \
        https://**put_your_bitrix24_address**/rest/**put_your_user_id_here**/**put_your_webhook_here**/calendar.resource.booking.list
        
curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"filter":{"resourceIdList":[10,18,17]},"auth":"**put_access_token_here**"}' \
        https://**put_your_bitrix24_address**/rest/calendar.resource.booking.list
        
// callListMethod: Retrieves all data at once. Use only for small selections (< 1000 items) due to high memory usage.
        
        try {
          const response = await $b24.callListMethod(
            'calendar.resource.booking.list',
            {
              filter: {
                resourceIdList: [10, 18, 17]
              }
            },
            (progress) => { console.log('Progress:', progress) }
          )
          const items = response.getData() || []
          for (const entity of items) { console.log('Entity:', entity) }
        } catch (error) {
          console.error('Request failed', error)
        }
        
        // fetchListMethod: Retrieves data in parts using an iterator. Use it for large data volumes to optimize memory usage.
        
        try {
          const generator = $b24.fetchListMethod('calendar.resource.booking.list', {
            filter: {
              resourceIdList: [10, 18, 17]
            }
          }, 'ID')
          for await (const page of generator) {
            for (const entity of page) { console.log('Entity:', entity) }
          }
        } catch (error) {
          console.error('Request failed', error)
        }
        
        // callMethod: Manually controls pagination through the start parameter. Use it for precise control of request batches. For large datasets, it is less efficient than fetchListMethod.
        
        try {
          const response = await $b24.callMethod('calendar.resource.booking.list', {
            filter: {
              resourceIdList: [10, 18, 17]
            }
          }, 0)
          const result = response.getData().result || []
          for (const entity of result) { console.log('Entity:', entity) }
        } catch (error) {
          console.error('Request failed', error)
        }
        
try {
            $response = $b24Service
                ->core
                ->call(
                    'calendar.resource.booking.list',
                    [
                        'filter' => [
                            'resourceIdList' => [10, 18, 17]
                        ]
                    ]
                );
        
            $result = $response
                ->getResponseData()
                ->getResult();
        
            echo 'Success: ' . print_r($result, true);
            // Your logic for processing data
            processData($result);
        
        } catch (Throwable $e) {
            error_log($e->getMessage());
            echo 'Error fetching resource booking list: ' . $e->getMessage();
        }
        
BX24.callMethod(
            'calendar.resource.booking.list',
            {
                filter: {
                    resourceIdList: [10, 18, 17]
                }
            }
        );
        
require_once('crest.php');
        
        $result = CRest::call(
            'calendar.resource.booking.list',
            [
                'filter' => [
                    'resourceIdList' => [10, 18, 17]
                ]
            ]
        );
        
        echo '<PRE>';
        print_r($result);
        echo '</PRE>';
        

Response Handling

HTTP Status: 200

{
            "result": [
                {
                    "ID": "1408",
                    "PARENT_ID": "1408",
                    "DELETED": "N",
                    "CAL_TYPE": "resource",
                    "OWNER_ID": "0",
                    "NAME": "Booking",
                    "DATE_FROM": "20.12.2024 00:00:00",
                    "DATE_TO": "21.12.2024 00:00:00",
                    "TZ_FROM": "Europe/Riga",
                    "TZ_TO": "Europe/Riga",
                    "TZ_OFFSET_FROM": "7200",
                    "TZ_OFFSET_TO": "7200",
                    "DATE_FROM_TS_UTC": "1734652800",
                    "DATE_TO_TS_UTC": "1734739200",
                    "DT_SKIP_TIME": "Y",
                    "DT_LENGTH": 172800,
                    "EVENT_TYPE": "#resourcebooking#",
                    "CREATED_BY": "1",
                    "DATE_CREATE": "18.12.2024 13:55:35",
                    "TIMESTAMP_X": "18.12.2024 13:55:35",
                    "DESCRIPTION": "Service: some",
                    "IS_MEETING": false,
                    "MEETING_STATUS": "Y",
                    "MEETING_HOST": "0",
                    "VERSION": "1",
                    "SECTION_ID": "198",
                    "DATE_FROM_FORMATTED": "Fri Dec 20 2024",
                    "DATE_TO_FORMATTED": "Sat Dec 21 2024",
                    "SECT_ID": "198",
                    "RESOURCE_BOOKING_ID": "10"
                },
                {
                    "ID": "1409",
                    ...
                }
            ],
            "time": {
                "start": 1733318565.183275,
                "finish": 1733318565.695058,
                "duration": 0.5117831230163574,
                "processing": 0.29406094551086426,
                "date_start": "2024-12-04T13:22:45+00:00",
                "date_finish": "2024-12-04T13:22:45+00:00"
            }
        }
        

Returned Data

Name
type

Description

result
array

Array of objects. Each object describes a booking

Booking Object

Technically, a booking is a calendar event. The method retrieves a set of fields similar to those of a calendar event. Some fields remain empty as they are not relevant for bookings. Below are only the relevant or filled fields.

Name
type

Description

ID
string

Booking identifier

PARENT_ID
string

For a booking object, always equal to the ID field

DELETED
string

Flag indicating whether the booking is deleted. Possible values:

  • Y — booking deleted
  • N — booking not deleted

CAL_TYPE
string

Type of calendar in which the booking is located

OWNER_ID
string

For a booking object, always equals '0'

NAME
string

Name of the booking

DATE_FROM
datetime

Start date of the booking

DATE_TO
datetime

End date of the booking

TZ_FROM
string

Timezone of the start date of the booking

TZ_TO
string

Timezone of the end date of the booking

TZ_OFFSET_FROM
string

Time offset of the start of the booking relative to UTC in seconds

TZ_OFFSET_TO
string

Time offset of the end of the booking relative to UTC in seconds

DATE_FROM_TS_UTC
string

Start date and time of the booking in UTC in timestamp format

DATE_TO_TS_UTC
string

End date and time of the booking in UTC in timestamp format

DT_SKIP_TIME
string

Flag indicating whether the booking lasts all day. Possible values:

  • Y — all day
  • N — not all day

DT_LENGTH
integer

Duration of the booking in seconds

EVENT_TYPE
string

Type of booking

CREATED_BY
string

Identifier of the user who created the booking

DATE_CREATE
datetime

Creation date of the booking

TIMESTAMP_X
datetime

Date of modification of the booking

DESCRIPTION
string

Description of the booking

IS_MEETING
boolean

For a booking object, always false

MEETING_STATUS
string

For a booking object, always 'Y'

MEETING_HOST
string

For a booking object, always '0'

VERSION
string

Version of booking changes

SECTION_ID
string

Identifier of the resource in which the booking is located

DATE_FROM_FORMATTED
string

Formatted start date of the booking

DATE_TO_FORMATTED
string

Formatted end date of the booking

SECT_ID
string

Identifier of the resource in which the booking is located

RESOURCE_BOOKING_ID
integer

Booking identifier

Error Handling

HTTP Status: 400

{
            "error": "",
            "error_description": "The required parameter "filter['resourceTypeIdList']" is not set for the method "calendar.resource.booking.list""
        }
        

Name
type

Description

error
string

String error code. It may consist of digits, Latin letters, and underscores

error_description
error_description

Textual description of the error. The description is not intended to be shown to the end user in its raw form

Possible Error Codes

Code

Error Message

Description

Empty string

Access denied

Access to the method is prohibited for external users

Empty string

The required parameter "filter['resourceTypeIdList']" is not set for the method "calendar.resource.booking.list"

Neither of the required parameters: resourceTypeIdList or resourceIdList was provided.

Statuses and System Error Codes

HTTP Status: 20x, 40x, 50x

The errors described below may occur when calling any method.

Status

Code
Error Message

Description

500

INTERNAL_SERVER_ERROR
Internal server error

An internal server error has occurred, please contact the server administrator or Bitrix24 technical support

500

ERROR_UNEXPECTED_ANSWER
Server returned an unexpected response

An internal server error has occurred, please contact the server administrator or Bitrix24 technical support

503

QUERY_LIMIT_EXCEEDED
Too many requests

The request intensity limit has been exceeded

405

ERROR_BATCH_METHOD_NOT_ALLOWED
Method is not allowed for batch usage

The current method is not allowed to be called using batch

400

ERROR_BATCH_LENGTH_EXCEEDED
Max batch length exceeded

The maximum length of parameters passed to the batch method has been exceeded

401

NO_AUTH_FOUND
Wrong authorization data

Invalid access token or webhook code

400

INVALID_REQUEST
Https required

The methods must be called using the HTTPS protocol

503

OVERLOAD_LIMIT
REST API is blocked due to overload

The REST API is blocked due to overload. This is a manual individual block, to remove it you need to contact Bitrix24 technical support

403

ACCESS_DENIED
REST API is available only on commercial plans

The REST API is available only on commercial plans

403

INVALID_CREDENTIALS
Invalid request credentials

The user whose access token or webhook was used to call the method lacks permissions

404

ERROR_MANIFEST_IS_NOT_AVAILABLE
Manifest is not available

The manifest is not available

403

insufficient_scope
The request requires higher privileges than provided by the webhook token

The request requires higher privileges than those provided by the webhook token

401

expired_token
The access token provided has expired

The provided access token has expired

403

user_access_error
The user does not have access to the application

The user does not have access to the application. This means that the application is installed, but the account administrator has allowed access to this application only for specific users

500

PORTAL_DELETED
Portal was deleted

The public part of the site is closed. To open the public part of the site on an on-premise installation, disable the option "Temporary closure of the public part of the site". Path to the setting: Desktop > Settings > Product Settings > Module Settings > Main Module > Temporary closure of the public part of the site

Continue Learning