Set Up the Widget Handler placement.bind

Scope: placement, depending on the placement location

Who can execute the method: administrator

The method placement.bind adds a handler for the widget placement.

It can be called at any time during the application's operation; however, it is often more convenient to register your widgets during the application installation.

It is important to note that until the application installation is complete, the widgets you register will not be available to regular users in the Bitrix24 interface—they will only be visible to users with administrative rights.
Check the application installation.

Method Parameters

Required parameters are marked with *

Name
type

Description

PLACEMENT*
string

Identifier for the required widget placement location

HANDLER*
string

URL of the widget placement handler

TITLE
string

Name of the widget in the interface. Depending on the specific placement location, this may be the name of a tab in a form, a menu item, etc.

DESCRIPTION
string

Description of the widget in the interface. Not used in practice

GROUP_NAME
string

Allows grouping UI elements for multiple handlers of the same widget type. For example, several dropdown items in the top button of the CRM card. Supported only by certain types of widgets

LANG_ALL
object

Array of parameters TITLE, DESCRIPTION, and GROUP_NAME for specified languages. Users who have selected one of these languages in the Bitrix24 interface will see localized versions of TITLE, DESCRIPTION, and GROUP_NAME:


            "LANG_ALL": {
                "en": {
                    "TITLE": "title",
                    "DESCRIPTION": "description",
                    "GROUP_NAME": "group"
                },
                "de": {
                    "TITLE": "Titel",
                    "DESCRIPTION": "Beschreibung",
                    "GROUP_NAME": "Gruppe"
                }
            }
        
        

OPTIONS
object

Additional display parameters for the widget. Specific values depend on the widget placement location. Currently used in widgets for messengers, in the widget PAGE_BACKGROUND_WORKER, and in the widget CRM_XXX_DETAIL_ACTIVITY

USER_ID
integer

Identifier of the Bitrix24 user for whom the registered widget will be available. Possible values can be obtained using the user.get method.

Currently, this parameter is only supported by the widget PAGE_BACKGROUND_WORKER.

If you attempt to register a placement in other widgets, you will receive the error ERROR_PLACEMENT_USER_MODE: User mode is not available.

Code Examples

How to Use Examples in Documentation

curl -X POST \
        -H "Content-Type: application/json" \
        -H "Accept: application/json" \
        -d '{"PLACEMENT":"PLACEMENT_CODE","HANDLER":"http://myapp.com/handler/?type=1","OPTIONS":{"errorHandlerUrl":"http://myapp.com/error/"},"TITLE":"title","DESCRIPTION":"description","GROUP_NAME":"group","LANG_ALL":{"en":{"TITLE":"title","DESCRIPTION":"description","GROUP_NAME":"group"},"de":{"TITLE":"Titel","DESCRIPTION":"Beschreibung","GROUP_NAME":"Gruppe"}},"auth":"**put_access_token_here**"}' \
        https://**put_your_bitrix24_address**/rest/placement.bind
        
try
        {
        	const response = await $b24.callMethod(
        		"placement.bind",
        		{ 
        			"PLACEMENT": "PLACEMENT_CODE",
        			"HANDLER": "http://myapp.com/handler/?type=1",
        			"OPTIONS": {
        				"errorHandlerUrl": "http://myapp.com/error/"
        			},
        			"TITLE": "title",
        			"DESCRIPTION": "description",
        			"GROUP_NAME": "group",
        			"LANG_ALL": {
        				"en": {
        					"TITLE": "title",
        					"DESCRIPTION": "description",
        					"GROUP_NAME": "group",
        				},
        				"de": {
        					"TITLE": "Titel",
        					"DESCRIPTION": "Beschreibung",
        					"GROUP_NAME": "Gruppe",
        				}
        			}
        		}
        	);
        	
        	const result = response.getData().result;
        	if(result.error())
        		console.error(result.error());
        	else
        		console.info(result);
        }
        catch(error)
        {
        	console.error('Error:', error);
        }
        
try {
            $response = $b24Service
                ->core
                ->call(
                    'placement.bind',
                    [
                        'PLACEMENT' => 'PLACEMENT_CODE',
                        'HANDLER' => 'http://myapp.com/handler/?type=1',
                        'OPTIONS' => [
                            'errorHandlerUrl' => 'http://myapp.com/error/'
                        ],
                        'TITLE' => 'title',
                        'DESCRIPTION' => 'description',
                        'GROUP_NAME' => 'group',
                        'LANG_ALL' => [
                            'en' => [
                                'TITLE' => 'title',
                                'DESCRIPTION' => 'description',
                                'GROUP_NAME' => 'group',
                            ],
                            'de' => [
                                'TITLE' => 'Titel',
                                'DESCRIPTION' => 'Beschreibung',
                                'GROUP_NAME' => 'Gruppe',
                            ]
                        ]
                    ]
                );
        
            $result = $response
                ->getResponseData()
                ->getResult();
        
            if ($result->error()) {
                error_log($result->error());
            } else {
                echo 'Success: ' . print_r($result->data(), true);
            }
        
        } catch (Throwable $e) {
            error_log($e->getMessage());
            echo 'Error binding placement: ' . $e->getMessage();
        }
        
BX24.callMethod(
            "placement.bind",
            { 
                "PLACEMENT": "PLACEMENT_CODE",
                "HANDLER": "http://myapp.com/handler/?type=1",
                "OPTIONS": {
                    "errorHandlerUrl": "http://myapp.com/error/"
                },
                "TITLE": "title",
                "DESCRIPTION": "description",
                "GROUP_NAME": "group",
                "LANG_ALL": {
                    "en": {
                        "TITLE": "title",
                        "DESCRIPTION": "description",
                        "GROUP_NAME": "group",
                    },
                    "de": {
                        "TITLE": "Titel",
                        "DESCRIPTION": "Beschreibung",
                        "GROUP_NAME": "Gruppe",
                    }
                }
            },
            function(result)
            {
                if(result.error())
                    console.error(result.error());
                else
                    console.info(result.data());
            }
        );
        
require_once('crest.php');
        
        $result = CRest::call(
            'placement.bind',
            [
                'PLACEMENT' => 'PLACEMENT_CODE',
                'HANDLER' => 'http://myapp.com/handler/?type=1',
                'OPTIONS' => [
                    'errorHandlerUrl' => 'http://myapp.com/error/'
                ],
                'TITLE' => 'title',
                'DESCRIPTION' => 'description',
                'GROUP_NAME' => 'group',
                'LANG_ALL' => [
                    'en' => [
                        'TITLE' => 'title',
                        'DESCRIPTION' => 'description',
                        'GROUP_NAME' => 'group'
                    ],
                    'de' => [
                        'TITLE' => 'Titel',
                        'DESCRIPTION' => 'Beschreibung',
                        'GROUP_NAME' => 'Gruppe'
                    ]
                ]
            ]
        );
        
        echo '<PRE>';
        print_r($result);
        echo '</PRE>';
        

Response Handling

HTTP status: 200

{
            "result": true,
            "time": {
                "start": 1712132792.910734,
                "finish": 1712132793.530359,
                "duration": 0.6196250915527344,
                "processing": 0.032338857650756836,
                "date_start": "2024-04-03T10:26:32+02:00",
                "date_finish": "2024-04-03T10:26:33+02:00",
                "operating_reset_at": 1705765533,
                "operating": 3.3076241016387939
            }
        }
        

Returned Data

Name
type

Description

result
boolean

Returns the result of adding the widget handler. Possible values:

  • True, the handler was successfully registered;
  • False, the handler was not registered

time
time

Information about the request execution time

Error Handling

HTTP status: 400, 403, 200

{
            "error": "ERROR_ARGUMENT",
            "error_description": "Argument 'PLACEMENT' is null or empty",
            "argument": "PLACEMENT"
        }
        

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

Description

Status

ERROR_PLACEMENT_MAX_COUNT

Attempted to re-register the handler for the widget PAGE_BACKGROUND_WORKER

200

ERROR_ARGUMENT

A required field value is missing. The code of the required field is returned in argument

200

WRONG_AUTH_TYPE

Current authorization type is denied for this method Application context required

403

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

Widget Handler

Thus, a successful call to the method placement.bind has allowed you to register a widget handler. It is important that the HANDLER_URL parameter you specify points to a real and accessible URL.

Important

It is required that the handler URL is definitely accessible from the external network. Links to localhost, local domains, and similar ways to access a local web server are not acceptable. Check the accessibility of the URL you specified using special services that monitor website availability!

When accessing your handler, Bitrix24 will send a POST message containing information about the widget context, such as the deal identifier if the widget is embedded in the deal card in CRM, etc.

You will find examples of such data in the descriptions of specific widget placement locations.

Continue Learning