UNPKG

@bitrix24/b24jssdk

Version:

Bitrix24 REST API JavaScript SDK

74 lines (70 loc) • 3.07 kB
/** * @package @bitrix24/b24jssdk * @version 3.0.0 * @copyright (c) 2026 Bitrix24 * @license MIT * @see https://github.com/bitrix24/b24jssdk * @see https://bitrix24.github.io/b24jssdk/ */ 'use strict'; const abstractAction = require('../abstract-action.cjs'); const b24 = require('../../../types/b24.cjs'); var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); class CallV3 extends abstractAction.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: `tasks.task.get`) * - `params?: TypeCallParamsV3` - Parameters for calling the method. * - `requestId?: string` - Unique 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). * - `idempotencyKey?: string` - `Idempotency-Key` header; a repeat with the same key and body * replays the stored response instead of writing again. * Server-side only: in a browser it throws `JSSDK_HTTP_IDEMPOTENCY_KEY_BROWSER` (#573). * * @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) * * @example * declare const orderId: number * // A write that is safe to retry: the same key means the same operation. * // Derive the key from your own identifiers rather than minting one at the * // call site — a `crypto.randomUUID()` here would be a fresh key on every * // attempt, so a retry from another process would still write a duplicate. * const created = await b24.actions.v3.call.make<{ item: { id: number } }>({ * method: 'tasks.task.add', * params: { fields: { title: 'Ship it', creatorId: 1, responsibleId: 1 } }, * idempotencyKey: `ship-task-for-order-${orderId}` * }) * // Sending the very same call again returns the very same task, * // and `created.isIdempotentReplay()` is `true` on that second response. */ async make(options) { const params = options.params || {}; return this._b24.getHttpClient(b24.ApiVersion.v3).call( options.method, params, options.requestId, void 0 === options.idempotencyKey ? void 0 : { idempotencyKey: options.idempotencyKey } ); } } exports.CallV3 = CallV3; //# sourceMappingURL=call.cjs.map