@bitrix24/b24jssdk
Version:
Bitrix24 REST API JavaScript SDK
72 lines (69 loc) • 3.03 kB
JavaScript
/**
* @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/
*/
import { AbstractAction } from '../abstract-action.mjs';
import { ApiVersion } from '../../../types/b24.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: `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(ApiVersion.v3).call(
options.method,
params,
options.requestId,
void 0 === options.idempotencyKey ? void 0 : { idempotencyKey: options.idempotencyKey }
);
}
}
export { CallV3 };
//# sourceMappingURL=call.mjs.map