Skip to content

B24Hook Class

Designed for managing Bitrix24 webhooks. It inherits functionality from AbstractB24 and provides methods for working with authentication via webhooks.

Implements the TypeB24 interface.

TIP

You can test working with B24Hook in this example.

Constructor

ts
constructor(b24HookParams: B24HookParams)

The B24HookParams type describes the webhook parameters used to initialize the authorization manager and HTTP client:

FieldTypeDescription
b24UrlstringBitrix24 portal URL, e.g., https://your-bitrix-portal.bitrix24.com.
userIdnumberUser identifier.
secretstringSecret key.

Methods

INFO

Implements the TypeB24 interface.

Usage

This code creates an instance of B24Hook to interact with the Bitrix24 API and performs a batch request to retrieve a list of companies, sorting them by ID in descending order.

The retrieved data is transformed into an array of objects with fields id, title, and createdTime, after which the results are logged to the console, and in case of an error, an error message is displayed.

ts
import {
	B24Hook,
	Text,
	EnumCrmEntityTypeId,
	LoggerBrowser,
	Result,
	type ISODate
} from '@bitrix24/b24jssdk'

const $logger = LoggerBrowser.build('MyApp', import.meta.env?.DEV === true)

const $b24 = new B24Hook({
	b24Url: 'https://your_domain.bitrix24.com',
	userId: 123,
	secret: 'k32t88gf3azpmwv3',
})

$b24.callBatch({
	CompanyList: {
		method: 'crm.item.list',
		params: {
			entityTypeId: EnumCrmEntityTypeId.company,
			order: { id: 'desc' },
			select: [
				'id',
				'title',
				'createdTime'
			]
		}
	}
}, true)
	.then((response: Result) => {
		const data = response.getData()
		const dataList = (data.CompanyList.items || []).map((item: any) => {
			return {
				id: Number(item.id),
				title: item.title,
				createdTime: Text.toDateTime(item.createdTime as ISODate)
			}
		})
		$logger.info('response >> ', dataList)
	})
	.catch((error) => {
		$logger.error(error)
	})
	.finally(() => {
		$logger.info('load >> stop ')
	})

Released under the MIT License.