Register a new event handler event.bind

Who can execute the method: any user

The method event.bind registers a new event handler.

The method works only in the context of application authorization. It can operate both under a user with portal administration rights and under a regular user. The method for a user without administrator rights is available with limitations:

  1. Offline events are not available; attempting to set them will raise an exception.
  2. Events are set on behalf of the current user (see the description of the auth_type parameter). Explicitly specifying an auth_type different from the ID of the current user will also raise an exception.

Note

Since requests will come from Bitrix servers, any URL must be accessible for GET/POST requests from the outside.

The interface for this method is BX24.callBind.

Note

When deleting and updating the application, its actions will be removed. Therefore, in the installer of each version, they need to be set from scratch.

Method Parameters

Required parameters are marked with *

Name
type

Description

event*
string

Event name

handler*
string

Link to the event handler

auth_type
integer

User ID under which the event handler is authorized. By default, the authorization of the user whose actions triggered the event will be used

event_type
string

Values: online\|offline. By default, event_type=online, and the method's behavior does not change. If event_type=offline is called, the method works with offline events

auth_connector
string

Source key. This parameter is intended for offline events. It allows excluding false event triggers

options
string

Additional settings for the registered event, if any

Code Examples

How to Use Examples in Documentation

curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{
            "event": "ONCRMLEADADD",
            "handler": "https://www.my-domain.com/handler/",
            "auth": "**put_access_token_here**"
        }' \
        https://**put_your_bitrix24_address**/rest/event.bind
        
BX24.callBind(
            'ONCRMLEADADD',
            'https://www.my-domain.com/handler/',
            15,
            (result) => console.log(result)
        );
        
require_once('crest.php');
        
        $result = CRest::call(
            'event.bind',
            [
                'event' => 'ONCRMLEADADD',
                'handler' => 'https://www.my-domain.com/handler/',
                'auth_type' => 15
            ]
        );
        
        echo '<PRE>';
        print_r($result);
        echo '</PRE>';
        

Response Handling

HTTP status: 200

{
            "result": true,
            "time": {
                "start": 1721296536.908506,
                "finish": 1721296537.007365,
                "duration": 0.09885907173156738,
                "processing": 0.03251290321350098,
                "date_start": "2024-07-18T11:55:36+02:00",
                "date_finish": "2024-07-18T11:55:37+02:00",
                "operating": 0
            }
        }
        

Returned Data

Name
type

Description

result
boolean

Success of execution

time
time

Information about the execution time of the request

Error Handling

HTTP status: 400

{
            "error":"ERROR_EVENT_NOT_FOUND",
            "error_description":"Event not found"
        }
        

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

ERROR_EVENT_NOT_FOUND

Event not found

Incorrect event specified

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