v2.0.0

AjaxResult

Specialised Result returned by every REST helper. Provides isMore() / getNext() / getTotal() / getStatus() for paged responses, and immutable data.

AjaxResult<T> extends Result<Payload<T>> and is the type every actions.v{2,3}.call.make() resolves to. Compared to the generic Result, it:

  • accepts the raw REST response (answer), the original request (query), and the HTTP status, and freezes them — setData() throws.
  • decodes Bitrix24 error payloads into AjaxError instances stored under the key 'base-error'.
  • exposes pagination helpers (isMore, getNext, fetchNext, getTotal).
  • exposes the HTTP status (getStatus) and the original request (getQuery).

Reading Data

getData(): undefined | SuccessPayload<T>

Returns undefined when the result is not successful. On success, returns a frozen object with result, next, total, time (only the fields present in the original payload). Use T to type the underlying result:

const response = await $b24.actions.v2.call.make<{ id: number, title: string }[]>({
  method: 'crm.item.list',
  params: { entityTypeId: 4, select: ['id', 'title'] },
  requestId: 'list-companies'
})

if (!response.isSuccess) {
  throw new Error(response.getErrorMessages().join('; '))
}

const data = response.getData()!     // { result: { id, title }[], next?: number, total?: number, time }

Pagination

getNext / fetchNext are implemented for REST API v2 only. v3 throws SdkError({ code: 'JSSDK_CORE_METHOD_NOT_SUPPORT_IN_API_V3' }) — use actions.v3.fetchList.make instead.

isMore / hasMore

isMore(): boolean
hasMore(): boolean   // alias

true when the success payload contains a numeric next. Always false for unsuccessful results.

getNext

getNext(http: TypeHttp): Promise<AjaxResult<T> | false>

Re-runs the original method with params.start = next and returns a new AjaxResult<T>. Returns false when there is no next page or the current result is unsuccessful.

fetchNext

fetchNext(http: TypeHttp): Promise<AjaxResult<T> | null>

Same as getNext, but returns null instead of false.

getTotal / getStatus / getQuery

getTotal(): number
getStatus(): number
getQuery(): Readonly<AjaxQuery>

getTotal returns 0 on unsuccessful results. AjaxQuery captures { method, params, requestId }; the returned object and its params are stable — calling getNext() does not mutate them.

Error Handling

When the raw response carries a { error: ... } field, AjaxResult converts it to an AjaxError (subclass of SdkError) keyed by 'base-error' in the inherited errors map. Both v2 and v3 error shapes are handled, including v3 validation[] arrays.

import { AjaxError } from '@bitrix24/b24jssdk'

const response = await $b24.actions.v2.call.make({ method: 'profile', requestId: 'p' })
if (!response.isSuccess) {
  for (const error of response.getErrors()) {
    if (error instanceof AjaxError) {
      console.error(error.code, error.requestInfo?.method)
    }
  }
}

setData Is Disabled

setData(): never

Always throws ReferenceError('AjaxResult does not allow data modification'). Use higher-level helpers (callList, fetchList, batch) when you need to aggregate.