v2.2.0

CallV2.make

A method for making Bitrix24 REST API version 2 calls.
Bitrix24 is gradually transitioning to REST API version 3.
  • Where a method has a v3 form, prefer the explicit actions.v3.* surface — see available v3 methods.

Overview

Use CallV2.make() to call REST API version 2 methods.

The method returns a Promise with an AjaxResult object containing response data, status, and error handling methods.

// Basic usage
import { EnumCrmEntityTypeId } from '@bitrix24/b24jssdk'

const response = await $b24.actions.v2.call.make({
  method: 'crm.item.get',
  params: {
    entityTypeId: EnumCrmEntityTypeId.contact,
    id: 123
  },
  requestId: 'unique-request-id'
})

Method Signature

make<T = unknown>(
  options: ActionCallV2
): Promise<AjaxResult<T>>

Parameters

The options object contains the following properties:

ParameterTypeRequiredDescription
methodstringYesREST API method name (e.g., crm.item.get, tasks.task.get).
paramsTypeCallParamsNoObject with parameters to pass to the REST API method.
requestIdstringNoUnique request identifier for tracking and debugging — sent as the bx24_request_id query parameter. It does not deduplicate anything; for that see idempotencyKey (restApi:v3).

Return Value

Promise<AjaxResult<T>> — a promise that resolves to an AjaxResult object.

This object provides:

  • .getData(): SuccessPayload<T> | undefined — returns the success envelope { result: T, time?: PayloadTime }, or undefined when the request failed. Check .isSuccess first. time is optional — not every response carries one, and the SDK does not invent it.
  • .isSuccess: boolean — flag indicating successful request execution.
  • .getErrorMessages(): string[] — array of error messages.

Key Concepts

Error Handling

Always check the result using isSuccess and handle errors:

// @check-ignore: top-level return in error-handling illustration

const response = await $b24.actions.v2.call.make({
  method: 'some.method',
  params: { /* some_params */ },
  requestId: 'unique-request-id'
})

if (!response.isSuccess) {
  // Handling error
  console.error(new Error(`Error: ${response.getErrorMessages().join('; ')}`))
  return
}

// Working with a successful result
const data = response.getData()?.result

Examples

Getting a CRM Company

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

type Company = {
  id: number
  title: string
  [key: string]: any
}

const devMode = typeof import.meta !== 'undefined' && (import.meta?.dev || import.meta.env?.DEV)
const $logger = LoggerFactory.createForBrowser('Example:getCrmItem', devMode)
const $b24 = B24Hook.fromWebhookUrl('https://your_domain.bitrix24.com/rest/1/webhook_code/')

async function getCrmItem(entityTypeId: number, itemId: number, requestId: string): Promise<Company | null> {
  const response = await $b24.actions.v2.call.make<{ item: Company }>({
    method: 'crm.item.get',
    params: {
      entityTypeId: entityTypeId,
      id: itemId
    },
    requestId
  })

  if (!response.isSuccess) {
    throw new SdkError({
      code: 'MY_APP_GET_PROBLEM',
      description: `Problem ${response.getErrorMessages().join('; ')}`,
      status: 404
    })
  }

  return (response.getData()!.result as { item: Company }).item
}

// Usage
const itemId = 528
const requestId = `crm-item-${itemId}`
try {
  const entity = await getCrmItem(EnumCrmEntityTypeId.company, itemId, requestId)
  $logger.info(`Entity [${entity?.id}]`, { entity })
} catch (error) {
  if (error instanceof AjaxError) {
    $logger.critical(error.message, { requestId, code: error.code })
  } else {
    $logger.alert('Problem', { requestId, error })
  }
}

Long-Running Requests

Heavy non-idempotent methods like crm.documentgenerator.document.add routinely exceed the default 30-second axios timeout. On a timeout the SDK retries by default, which can create duplicate entities server-side (see issue #24).

For any method that creates or persists state, raise the axios timeout and disable retries on transport errors:

import { ApiVersion, ParamsFactory } from '@bitrix24/b24jssdk'

// const $b24 = ...
$b24.getHttpClient(ApiVersion.v2).ajaxClient.defaults.timeout = 120_000
await $b24.setRestrictionManagerParams({
  ...ParamsFactory.getDefault(),
  retryOnNetworkError: false
})

await $b24.actions.v2.call.make({
  method: 'crm.documentgenerator.document.add',
  params: {/*…*/}
})

See Limiters → Long-Running Requests & Non-idempotent Calls for the full explanation and alternative configurations.

Alternatives and Recommendations

  • For working with lists: Instead of manually managing pagination use:
    • CallList — automatically retrieves all pages and returns a single result.
    • FetchList — returns an async generator for step-by-step processing of large lists.
  • For batch operations: Use Batch to execute up to 50 commands in a single request.
  • On the client-side (browser): Use the built-in B24Frame object.