B24Hook object is intended exclusively for use on the server.- A webhook contains a secret access key, which MUST NOT be used in client-side code (browser, mobile app).
- For the client side, use
B24Frame.
Quick Overview
B24Hook is the main SDK class for working with the Bitrix24 REST API via webhooks. A webhook is a special URL that has authentication data (user ID and secret key) embedded in it. This allows making API requests without additional authorization.
Creating a B24Hook Instance
There are two ways to create a B24Hook instance:
From a Full Webhook URL
Use this method (recommended approach) if you have a ready-made webhook URL generated in Bitrix24.
import { B24Hook } from '@bitrix24/b24jssdk'
// Creating an instance from a full webhook URL
const $b24 = B24Hook.fromWebhookUrl('https://your_domain.bitrix24.com/rest/1/webhook_code/')
Method Signature
static fromWebhookUrl(
url: string
): B24Hook
Parameters
When to use:
- For rapid prototyping
- When the webhook URL is stored in server environment variables
From Parameters
Use this method if webhook parameters are stored separately.
import { B24Hook } from '@bitrix24/b24jssdk'
// Creating an instance from individual parameters
const $b24 = new B24Hook({
b24Url: 'https://your_domain.bitrix24.com',
userId: 1,
secret: 'webhook_code'
})
Constructor Signature
constructor(
b24HookParams: B24HookParams
)
Parameters
B24HookParams is an interface with the following fields:
When to use:
- When webhook parameters are stored in different environment variables
Example
Recommendations for Storing Webhook Data
// ✅ Storing in server environment variables
const $b24 = B24Hook.fromWebhookUrl(process.env.BITRIX24_WEBHOOK_URL!);
// ❌ NEVER store a webhook in client code
// ❌ NEVER commit a webhook to Git
const $b24 = B24Hook.fromWebhookUrl(
'https://company.bitrix24.com/rest/1/abcdef123456/'
); // DATA LEAK!
What to Do Next
After creating a B24Hook instance, you can use the following methods:
Core API methods:
- callMethod() — Call any REST API method
- callBatch() — Batch execution of up to 50 commands
Working with lists:
- callFastListMethod() — Automatic retrieval of all list pages
- fetchListMethod() — Incremental loading of large lists via generator
Advanced scenarios:
- callBatchByChunk() — Batch execution of any number of commands with automatic chunking
FAQ
Detailed information about WebHook is available in the Rest Api documentation
Yes, create one instance when the application starts and reuse it. This improves performance.
Check the following:
- Check settings, the webhook might have been deleted.
- Make sure the user has the necessary permissions.
- Verify the correctness of the URL or parameters.