UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

69 lines (66 loc) 2.43 kB
/** * @package @bitrix24/b24jssdk * @version 1.0.5 * @copyright (c) 2026 Bitrix24 * @license MIT * @see https://github.com/bitrix24/b24jssdk * @see https://bitrix24.github.io/b24jssdk/ */ import { AbstractAction } from '../abstract-action.mjs'; import { versionManager } from '../../version-manager.mjs'; import { ApiVersion } from '../../../types/b24.mjs'; import { LoggerFactory } from '../../../logger/logger-factory.mjs'; var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); class CallV2 extends AbstractAction { static { __name(this, "CallV2"); } /** * Calls the Bitrix24 REST API method. * * @template T - The expected data type in the response (default is `unknown`). * * @param {ActionCallV2} options - parameters for executing the request. * - `method: string` - REST API method name (eg: `crm.item.get`) * - `params?: TypeCallParams` - Parameters for calling the method. * - `requestId?: string` - Unique request identifier for tracking. Used for query deduplication and debugging. * * @returns {Promise<AjaxResult<T>>} A promise that resolves to the result of an REST API call. * * @example * import { EnumCrmEntityTypeId } from '@bitrix24/b24jssdk' * * interface CrmItem { id: number, name: string, lastName: string } * const response = await b24.actions.v2.call.make<{ item: CrmItem }>({ * method: 'crm.item.get', * params: { * entityTypeId: EnumCrmEntityTypeId.contact, * id: 123 * }, * requestId: 'item-123' * }) * if (!response.isSuccess) { * throw new Error(`Problem: ${response.getErrorMessages().join('; ')}`) * } * console.log(response.getData().result.item.name) */ async make(options) { if (versionManager.isSupport(ApiVersion.v3, options.method)) { LoggerFactory.forcedLog( this._logger, "warning", `The method ${options.method} is available in restApi:v3. It's worth migrating to the new API.`, { method: options.method, requestId: options.requestId, code: "JSSDK_CORE_METHOD_AVAILABLE_IN_API_V3" } ); } const params = options.params || {}; return this._b24.getHttpClient(ApiVersion.v2).call(options.method, params, options.requestId); } } export { CallV2 }; //# sourceMappingURL=call.mjs.map