Set Up the Widget Handler placement.bind
Scope:
placement,depending on the placement locationWho 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 |
Description |
|
PLACEMENT* |
Identifier for the required widget placement location |
|
HANDLER* |
URL of the widget placement handler |
|
TITLE |
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 |
Description of the widget in the interface. Not used in practice |
|
GROUP_NAME |
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 |
Array of parameters
|
|
OPTIONS |
Additional display parameters for the widget. Specific values depend on the widget placement location. Currently used in widgets for messengers, in the widget |
|
USER_ID |
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 If you attempt to register a placement in other widgets, you will receive the error |
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>';
Typical use-cases and scenarios
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 |
Description |
|
result |
Returns the result of adding the widget handler. Possible values:
|
|
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 |
Description |
|
error |
String error code. It may consist of digits, Latin letters, and underscores |
|
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 |
|
|
Attempted to re-register the handler for the widget |
200 |
|
|
A required field value is missing. The code of the required field is returned in |
200 |
|
|
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 |
Description |
|
|
|
An internal server error has occurred, please contact the server administrator or Bitrix24 technical support |
|
|
|
An internal server error has occurred, please contact the server administrator or Bitrix24 technical support |
|
|
|
The request intensity limit has been exceeded |
|
|
|
The current method is not allowed to be called using batch |
|
|
|
The maximum length of parameters passed to the batch method has been exceeded |
|
|
|
Invalid access token or webhook code |
|
|
|
The methods must be called using the HTTPS protocol |
|
|
|
The REST API is blocked due to overload. This is a manual individual block, to remove it you need to contact Bitrix24 technical support |
|
|
|
The REST API is available only on commercial plans |
|
|
|
The user whose access token or webhook was used to call the method lacks permissions |
|
|
|
The manifest is not available |
|
|
|
The request requires higher privileges than those provided by the webhook token |
|
|
|
The provided access token has expired |
|
|
|
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 |
|
|
|
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
- Widget Embedding Locations
- Retrieving a List of Available Placement Options for the Application
- Removing a Registered Placement Handler
- Interaction with UI from Widgets