@todo fix me!
v1.0.1
  • Get Started
  • Templates
  • GitHub
  • Overview
  • Introduction
  • Installation
  • Vue
  • Nuxt
  • NodeJs
  • UMD
  • AI Tools
  • MCP Server
  • LLMs.txt
  • b24ui
  • b24icons
v1.0.1
  • Docs
  • Frame
  • Hook
  • OAuth
  • Templates

NodeJs Project

Complete guide for installing and using Bitrix24 JS SDK in NodeJs applications.
We are still updating this page. Some data may be missing here — we will complete it shortly.

Setup

Since version 0.4.0 CommonJs is not supported. Only ESM and UMD.

Before you begin, make sure you have the latest version of Node.js installed.

We support version NodeJs ^18.0.0 || ^20.0.0 || >=22.0.0

Then run the following command to install the library:

Install the Bitrix24 JS SDK package

pnpm add @bitrix24/b24jssdk
yarn add @bitrix24/b24jssdk
npm install @bitrix24/b24jssdk
bun add @bitrix24/b24jssdk

Import

Import the library into your project:

import { B24Hook } from '@bitrix24/b24jssdk'

Example

Here's a simple example demonstrating how to get a list of companies.

For simplicity, B24Hook is used.

import { B24Hook, Text, EnumCrmEntityTypeId, LoggerFactory } from '@bitrix24/b24jssdk'

// Initialize logger
const $logger = LoggerFactory.createForBrowser('B24/jsSdk::nodeJs', process.env.NODE_ENV === 'development')

// Create B24Hook instance for Node.js
let hookPath = ''
hookPath = process.env?.B24_HOOK || ''
if (hookPath.length < 1) {
  $logger.error(`🚨 Wrong hook! Set it on .env file`)
  process.exit(1)
}
const $b24 = B24Hook.fromWebhookUrl(hookPath)
$logger.info(`Used Bitrix24: ${$b24.getTargetOrigin()}`)

/**
 * Load company list
 */
async function loadCompanies() {
  if (!$b24) {
    throw new Error('$b24 not init')
  }

  try {
    $logger.info('Loading companies...')

    const response = await $b24.callMethod(
      'crm.item.list',
      {
        entityTypeId: EnumCrmEntityTypeId.company,
        order: { id: 'desc' },
        select: ['id', 'title', 'createdTime']
      }
    )

    const data = response.getData().result

    const dataList = (data?.items || []).map(item => ({
      id: Number(item.id),
      title: item.title,
      createdTime: Text.toDateTime(item.createdTime) // @memo this is luxon/DateTime
    }))

    $logger.info('Companies loaded successfully:', dataList)

    return dataList
  } catch (error) {
    $logger.error('Request failed', { error })
    throw error
  } finally {
    $logger.info('Request processing completed')
  }
}

/**
 * Format data for console output
 */
function formatCompaniesForConsole(companies) {
  if (companies.length === 0) {
    return 'No companies found'
  }

  const header = '┌──────┬──────────────────────────────┬─────────────────────┐'
  const footer = '└──────┴──────────────────────────────┴─────────────────────┘'

  const rows = companies.map((company) => {
    const id = `#${company.id}`.padEnd(4)
    const title = (company.title || 'No title').substring(0, 28).padEnd(28)
    const date = company.createdTime.toFormat('yyyy-MM-dd HH:mm:ss')
    return `│ ${id} │ ${title} │ ${date} │`
  })

  return [
    header,
    '│ ID   │ Title                        │ Created Date        │',
    '├──────┼──────────────────────────────┼─────────────────────┤',
    ...rows,
    footer
  ].join('\n')
}

/**
 * Main function
 */
async function main() {
  try {
    const companies = await loadCompanies()

    // Data processing
    $logger.info(`Loaded ${companies.length} companies`)

    // Output data to console
    console.log('\n' + formatCompaniesForConsole(companies))
    if (companies.length > 0) {
      const latestCompany = companies[0]
      $logger.info(`Latest company: ${latestCompany.title} (ID: ${latestCompany.id})`)
    }
  } catch (error) {
    $logger.error('Failed to load companies', { error })
    process.exit(1)
  }
}

/**
 * Process error handlers
 */
function setupProcessHandlers() {
  process.on('unhandledRejection', (reason, promise) => {
    $logger.error('Unhandled Rejection', { promise, reason })
    process.exit(1)
  })

  process.on('uncaughtException', (error) => {
    $logger.error('Uncaught Exception:', { error })
    process.exit(1)
  })
}

// Startup
setupProcessHandlers()
main()
  .then(() => {
    $logger.info('👋 Application completed successfully')
    process.exit(0)
  })
  .catch((error) => {
    $logger.error('💥 Application failed:', { error })
    process.exit(1)
  })
{
  "name": "demo/b24-js-sdk-cli",
  "scripts": {
    "action:get-company-list": "node -r dotenv/config ./scripts/get-company-list.mjs",
  },
  "devDependencies": {
    "@types/node": "^24.7.0",
    "dotenv": "^17.2.3"
  }
}
B24_HOOK=https://your-domain.bitrix24.com/rest/your-user-id/your-webhook-code/

Documentation

B24Hook

To work with Bitrix24 from a standalone application using Hook

B24OAuth

To work with Bitrix24 from a standalone application using OAuth

Nuxt

Complete guide for installing and using Bitrix24 JS SDK in Nuxt applications.

UMD

Complete guide for using UMD version Bitrix24 JS SDK in you applications.

On this page

  • Setup
  • Example
  • Documentation
Releases
Published under MIT License.

Copyright © 2024-present Bitrix24