Push&Pull in the Browser
Choose a tool for developing with an AI agent:
- use Alaio Vibecode to build an app for Bitrix24 from a task description without knowing any programming language. The agent writes the code and deploys the app to a server, with no manual hosting setup
- use the MCP server to develop a REST API integration in your own project. The agent refers to the official REST documentation
The built-in BX.PullClient keeps a connection to the Push&Pull servers and delivers events sent by the application's server side with pull.application.event.add to the browser. The application interface updates immediately, without polling the server or reloading the page.
The client runs on the application page and requests the configuration again on its own when the channel expires. If the application runs outside the Bitrix24 interface and the built-in client is not enough, you will have to maintain the connection yourself — this is described in the Custom Push&Pull Client article.
The client works only in the context of an application. It requests the connection configuration with the pull.application.config.get method, which requires an OAuth token and the pull scope, and a webhook does not create such a context.
Before You Start
- an installed application with an interface
- the
pullscope
The client needs two libraries from api.bitrix24.com: api/v1/ provides the BX24 object for REST calls, and api/v1/pull/ provides the BX.PullClient constructor.
How to Connect the Client
- Include the
api/v1/andapi/v1/pull/libraries in the<head>of the page - Wait until
BX24is ready: perform the remaining steps insideBX24.init - Retrieve the user ID with the user.current method
- Create the client with
new BX.PullClient()and pass the parameters - Subscribe to events with the
subscribemethod - Start the connection with the
startmethod
<!DOCTYPE html>
<html>
<head>
<title>Bitrix24 application with Push & Pull</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="//api.bitrix24.com/api/v1/"></script>
<script src="//api.bitrix24.com/api/v1/pull/"></script>
</head>
<body>
<script>
BX24.init(function () {
BX24.callMethod('user.current', {}, function (result) {
if (result.error()) {
console.error(result.error().ex);
return;
}
window.appPullClient = new BX.PullClient({
restApplication: 'my_app_pull',
restClient: BX24,
userId: Number(result.data().ID)
});
window.appPullClient.subscribe({
moduleId: 'application',
callback: function (data) {
console.warn(data); // {command: '...', params: {...}, extra: {...}}
}
});
window.appPullClient.start();
});
});
</script>
</body>
</html>
To make sure the client receives events, send an event from the server side with the pull.application.event.add method. The handler prints an object with the command, params, and extra fields to the browser console.
BX.PullClient Parameters
Required parameters are marked with *
|
Name |
Description |
|
restApplication* |
The application identifier. When it is set, the client requests the configuration with the pull.application.config.get method and connects to the application channels. The client also uses this value to retain the connection state in the browser, so set a stable string — one per application |
|
restClient* |
The object through which the client calls REST methods. In an application, pass |
|
userId* |
The ID of the current user. On an application page, the client has no way to retrieve it on its own, so the value is passed explicitly — in the example it is returned by user.current |
Subscribing to Events
The subscribe method registers a handler and returns a function that removes it:
const unsubscribe = window.appPullClient.subscribe({
moduleId: 'application',
callback: function (data) {
console.warn(data);
}
});
unsubscribe();
Required parameters are marked with *
|
Name |
Description |
|
moduleId* |
The module whose events the application needs. Events from the application channel have |
|
callback* |
The handler function. What it receives depends on whether the |
|
command |
The command the handler is subscribed to — the value of the |
|
type |
The event source. It is |
The command field determines the form in which the handler receives the data:
- without
command— the event arrives as a whole:callback(data, info), wheredatacontainscommand,params, andextra - with
command— the same data arrives unpacked:callback(params, extra, command, info)
In both forms, the last parameter the handler receives is info with the type and moduleId fields.
Continue Learning
- Interactivity in Applications: Overview of Methods
- Custom Push&Pull Client
- Get the Connection Configuration for Push&Pull Servers pull.application.config.get
- Send an Event to the Application Channel pull.application.event.add
- Send a Push Notification to the Application Users pull.application.push.add