UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

59 lines (56 loc) 2.14 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 { SdkError } from '../../sdk-error.mjs'; var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); class CallV3 extends AbstractAction { static { __name(this, "CallV3"); } /** * Calls the Bitrix24 REST API method. * * @template T - The expected data type in the response (default is `unknown`). * * @param {ActionCallV3} 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 * interface TaskItem { id: number, title: string } * const response = await b24.actions.v3.call.make<{ item: TaskItem }>({ * method: 'tasks.task.get', * params: { id: 123, select: ['id', 'title'] }, * requestId: 'task-123' * }) * if (!response.isSuccess) { * throw new Error(`Problem: ${response.getErrorMessages().join('; ')}`) * } * console.log(response.getData().result.item.title) */ async make(options) { if (!versionManager.isSupport(ApiVersion.v3, options.method)) { throw new SdkError({ code: "JSSDK_CORE_METHOD_NOT_SUPPORT_IN_API_V3", description: `restApi:v3 not support method ${options.method}`, status: 500 }); } const params = options.params || {}; return this._b24.getHttpClient(ApiVersion.v3).call(options.method, params, options.requestId); } } export { CallV3 }; //# sourceMappingURL=call.mjs.map