# Class TwinClient

#### Implements

- ITwinClient

##### Index

### Constructors

constructor

### Methods

batchAssets
batchGetAssets
createAssets
createOrUpdateTwin
createOrUpdateTwinFile
createOrUpdateTwinFileRaw
createOrUpdateTwinRaw
deleteAsset
deleteTwin
deleteTwinFile
downloadTwinContent
getAsset
getProcessorEvents
getTwin
getTwinContent
getTwinDiagnostics
getTwinFile
getTwinFileContent
getTwinFileVersion
getTwinFileVersionContent
getTwinVersionContent
getTwinVersionDiagnostics
getTwinVersionEvents
listAllTwins
listAssets
listTwinFiles
listTwinFileVersions
listTwins
listTwinVersions
loadGeometryInfo
loadGeometryInfoWithFactories
loadTwin
loadTwinWithFactories
loadTwinWithGeometry
restoreAsset
restoreTwin
restoreTwinFile
updateAsset
updateTwin

## Constructors

### constructor

- new TwinClient(
  baseUrl: string | URL,
  _httpClient: TwinfinityHttpClient,
  ): TwinClient

  #### Parameters

  - baseUrl: string | URL
  - _httpClient: TwinfinityHttpClient

  #### Returns TwinClient

## Methods

### batchAssets

- batchAssets(
  twinId: string,
  operations: AssetBatchOperation[],
  signal?: AbortSignal,
  ): Promise<AssetBatchResponse>

  Executes a batch of asset operations (upsert, delete, restore) atomically. All operations succeed or all are rolled back.

  #### Parameters

  - twinId: string
  - operations: AssetBatchOperation[]

    Array of batch operations (max 1000).

  - `Optional` signal: AbortSignal

  #### Returns Promise<AssetBatchResponse>

  #### Throws

  On validation failure (400).

  #### Throws

  On insufficient permissions (403).

  #### Throws

  On conflict (409) or not found (404). The error's `response` has per-item results with reverted statuses.

  Implementation of ITwinClient.batchAssets

### batchGetAssets

- batchGetAssets(
  twinId: string,
  ids: string[],
  signal?: AbortSignal,
  ): Promise<AssetBatchGetResponse>

  Retrieves multiple assets by ID in a single request.

  #### Parameters

  - twinId: string
  - ids: string[]

    Array of asset IDs (max 1000).

  - `Optional` signal: AbortSignal

  #### Returns Promise<AssetBatchGetResponse>

  #### Throws

  On validation failure (400).

  Implementation of ITwinClient.batchGetAssets

### createAssets

- createAssets(
  twinId: string,
  assets: AssetPost[],
  signal?: AbortSignal,
  ): Promise<AssetGet[]>

  #### Parameters

  - twinId: string
  - assets: AssetPost[]
  - `Optional` signal: AbortSignal

  #### Returns Promise<AssetGet[]>

  #### Throws

  On invalid request body (400). The error's `errorBody` has structured detail.

  Implementation of ITwinClient.createAssets

### createOrUpdateTwin

- createOrUpdateTwin(
  twinId: string,
  twin: TwinPut,
  signal?: AbortSignal,
  ): Promise<TwinGet>

  Creates a new twin or updates an existing one (upsert). Provide `etag` in the twin body to update.

  #### Parameters

  - twinId: string
  - twin: TwinPut
  - `Optional` signal: AbortSignal

  #### Returns Promise<TwinGet>

  #### Throws

  On invalid request body (400).

  #### Throws

  On etag mismatch (409). The error's `currentTwin` contains the server's current state.

  Implementation of ITwinClient.createOrUpdateTwin

### createOrUpdateTwinFile

- createOrUpdateTwinFile(
  twinId: string,
  fileId: string,
  twinFile: TwinFilePut,
  signal?: AbortSignal,
  ): Promise<TwinFileGet>

  #### Parameters

  - twinId: string
  - fileId: string
  - twinFile: TwinFilePut
  - `Optional` signal: AbortSignal

  #### Returns Promise<TwinFileGet>

  #### Throws

  On invalid request body (400).

  #### Throws

  On etag mismatch (409). The error's `currentTwinFile` contains the server's current state.

  Implementation of ITwinClient.createOrUpdateTwinFile

### createOrUpdateTwinFileRaw

- createOrUpdateTwinFileRaw(
  twinId: string,
  fileId: string,
  twinFile: unknown,
  signal?: AbortSignal,
  ): Promise<Response>

  #### Parameters

  - twinId: string
  - fileId: string
  - twinFile: unknown
  - `Optional` signal: AbortSignal

  #### Returns Promise<Response>

### createOrUpdateTwinRaw

- createOrUpdateTwinRaw(
  twinId: string,
  twin: unknown,
  signal?: AbortSignal,
  ): Promise<Response>

  #### Parameters

  - twinId: string
  - twin: unknown
  - `Optional` signal: AbortSignal

  #### Returns Promise<Response>

### deleteAsset

- deleteAsset(
  twinId: string,
  assetId: string,
  etag: string,
  signal?: AbortSignal,
  ): Promise<AssetGet>

  #### Parameters

  - twinId: string
  - assetId: string
  - etag: string
  - `Optional` signal: AbortSignal

  #### Returns Promise<AssetGet>

  #### Throws

  When the asset does not exist (404).

  #### Throws

  On etag mismatch (409). The error's `currentAsset` contains the server's current state.

  Implementation of ITwinClient.deleteAsset

### deleteTwin

- deleteTwin(twinId: string, etag: string, signal?: AbortSignal): Promise<TwinGet>

  #### Parameters

  - twinId: string
  - etag: string
  - `Optional` signal: AbortSignal

  #### Returns Promise<TwinGet>

  #### Throws

  When the twin does not exist (404).

  #### Throws

  On etag mismatch (409). The error's `currentTwin` contains the server's current state.

  Implementation of ITwinClient.deleteTwin

### deleteTwinFile

- deleteTwinFile(
  twinId: string,
  fileId: string,
  deleteRequest: TwinFileDelete,
  signal?: AbortSignal,
  ): Promise<TwinFileGet>

  #### Parameters

  - twinId: string
  - fileId: string
  - deleteRequest: TwinFileDelete
  - `Optional` signal: AbortSignal

  #### Returns Promise<TwinFileGet>

  #### Throws

  When the file does not exist (404).

  #### Throws

  On etag mismatch (409). The error's `currentTwinFile` contains the server's current state.

  #### Throws

  On invalid request (400).

  Implementation of ITwinClient.deleteTwinFile

### downloadTwinContent

- downloadTwinContent(
  twinId: string,
  twinVersion: number,
  content: TwinContentResponse,
  signal?: AbortSignal,
  ): Promise<ArrayBuffer>

  #### Parameters

  - twinId: string
  - twinVersion: number
  - content: TwinContentResponse
  - `Optional` signal: AbortSignal

  #### Returns Promise<ArrayBuffer>

  Implementation of ITwinClient.downloadTwinContent

### getAsset

- getAsset(
  twinId: string,
  assetId: string,
  signal?: AbortSignal,
  ): Promise<AssetGet>

  #### Parameters

  - twinId: string
  - assetId: string
  - `Optional` signal: AbortSignal

  #### Returns Promise<AssetGet>

  #### Throws

  When the asset does not exist (404).

  Implementation of ITwinClient.getAsset

### getProcessorEvents

- getProcessorEvents(
  twinId: string,
  twinVersion: number,
  processorId: string,
  offset?: number,
  limit?: number,
  signal?: AbortSignal,
  ): Promise<PaginatedResponse<TwinProcessorEvent>>

  #### Parameters

  - twinId: string
  - twinVersion: number
  - processorId: string
  - `Optional` offset: number
  - `Optional` limit: number
  - `Optional` signal: AbortSignal

  #### Returns Promise<PaginatedResponse<TwinProcessorEvent>>

  #### Throws

  On invalid query parameters (400).

  #### Throws

  When the processor does not exist for this twin version (404).

  Implementation of ITwinClient.getProcessorEvents

### getTwin

- getTwin(
  twin: string | { id: string; version: number },
  signal?: AbortSignal,
  ): Promise<TwinGet>

  #### Parameters

  - twin: string | { id: string; version: number }

    Twin ID string, or `{id, version}` to fetch a specific version.

  - `Optional` signal: AbortSignal

  #### Returns Promise<TwinGet>

  #### Throws

  When the twin or version does not exist (404).

  Implementation of ITwinClient.getTwin

### getTwinContent

- getTwinContent(
  twinId: string,
  signal?: AbortSignal,
  ): Promise<TwinVersionContentResponse>

  Returns content for the latest twin version.

  #### Parameters

  - twinId: string
  - `Optional` signal: AbortSignal

  #### Returns Promise<TwinVersionContentResponse>

  #### Throws

  When the twin does not exist (404).

  Implementation of ITwinClient.getTwinContent

### getTwinDiagnostics

- getTwinDiagnostics(
  twinId: string,
  signal?: AbortSignal,
  ): Promise<TwinDiagnosticsResponse>

  #### Parameters

  - twinId: string
  - `Optional` signal: AbortSignal

  #### Returns Promise<TwinDiagnosticsResponse>

  #### Throws

  When the twin does not exist (404).

  Implementation of ITwinClient.getTwinDiagnostics

### getTwinFile

- getTwinFile(
  twinId: string,
  fileId: string,
  signal?: AbortSignal,
  ): Promise<TwinFileGet>

  #### Parameters

  - twinId: string
  - fileId: string
  - `Optional` signal: AbortSignal

  #### Returns Promise<TwinFileGet>

  #### Throws

  When the file does not exist (404).

  #### Throws

  On invalid request (400).

  Implementation of ITwinClient.getTwinFile

### getTwinFileContent

- getTwinFileContent(
  twinId: string,
  fileId: string,
  signal?: AbortSignal,
  ): Promise<Blob>

  #### Parameters

  - twinId: string
  - fileId: string
  - `Optional` signal: AbortSignal

  #### Returns Promise<Blob>

  #### Throws

  When the file does not exist (404).

  Implementation of ITwinClient.getTwinFileContent

### getTwinFileVersion

- getTwinFileVersion(
  twinId: string,
  fileId: string,
  version: number,
  signal?: AbortSignal,
  ): Promise<TwinFileGet>

  #### Parameters

  - twinId: string
  - fileId: string
  - version: number
  - `Optional` signal: AbortSignal

  #### Returns Promise<TwinFileGet>

  #### Throws

  When the file or version does not exist (404).

  Implementation of ITwinClient.getTwinFileVersion

### getTwinFileVersionContent

- getTwinFileVersionContent(
  twinId: string,
  fileId: string,
  version: number,
  signal?: AbortSignal,
  ): Promise<Blob>

  #### Parameters

  - twinId: string
  - fileId: string
  - version: number
  - `Optional` signal: AbortSignal

  #### Returns Promise<Blob>

  #### Throws

  When the file or version does not exist (404).

  Implementation of ITwinClient.getTwinFileVersionContent

### getTwinVersionContent

- getTwinVersionContent(
  twinId: string,
  twinVersion: number,
  signal?: AbortSignal,
  ): Promise<TwinVersionContentResponse>

  #### Parameters

  - twinId: string
  - twinVersion: number
  - `Optional` signal: AbortSignal

  #### Returns Promise<TwinVersionContentResponse>

  #### Throws

  When the twin or version does not exist (404).

  Implementation of ITwinClient.getTwinVersionContent

### getTwinVersionDiagnostics

- getTwinVersionDiagnostics(
  twinId: string,
  twinVersion: number,
  signal?: AbortSignal,
  ): Promise<TwinDiagnosticsResponse>

  #### Parameters

  - twinId: string
  - twinVersion: number
  - `Optional` signal: AbortSignal

  #### Returns Promise<TwinDiagnosticsResponse>

  #### Throws

  When the twin or version does not exist (404).

  Implementation of ITwinClient.getTwinVersionDiagnostics

### getTwinVersionEvents

- getTwinVersionEvents(
  twinId: string,
  twinVersion: number,
  offset?: number,
  limit?: number,
  signal?: AbortSignal,
  ): Promise<PaginatedResponse<TwinProcessorEvent>>

  #### Parameters

  - twinId: string
  - twinVersion: number
  - `Optional` offset: number
  - `Optional` limit: number
  - `Optional` signal: AbortSignal

  #### Returns Promise<PaginatedResponse<TwinProcessorEvent>>

  #### Throws

  On invalid query parameters (400).

  #### Throws

  When the twin or version does not exist (404).

  Implementation of ITwinClient.getTwinVersionEvents

### listAllTwins

- listAllTwins(relatedTo?: string, signal?: AbortSignal): Promise<ListTwinItem[]>

  Fetches all twins by auto-paginating through listTwins. Caps at 1000 pages.

  #### Parameters

  - `Optional` relatedTo: string

    Filter twins by container ID.

  - `Optional` signal: AbortSignal

  #### Returns Promise<ListTwinItem[]>

  Implementation of ITwinClient.listAllTwins

### listAssets

- listAssets(
  twinId: string,
  offset?: number,
  limit?: number,
  options?: { includeDeleted?: boolean },
  signal?: AbortSignal,
  ): Promise<PaginatedResponse<AssetListItem>>

  #### Parameters

  - twinId: string
  - `Optional` offset: number
  - `Optional` limit: number
  - `Optional` options: { includeDeleted?: boolean }
  - `Optional` signal: AbortSignal

  #### Returns Promise<PaginatedResponse<AssetListItem>>

  #### Throws

  On invalid query parameters (400).

  #### Throws

  When the twin does not exist (404).

  Implementation of ITwinClient.listAssets

### listTwinFiles

- listTwinFiles(
  twinId: string,
  options?: TwinFileListOptions,
  signal?: AbortSignal,
  ): Promise<PaginatedResponse<TwinFileGet>>

  #### Parameters

  - twinId: string
  - `Optional` options: TwinFileListOptions
  - `Optional` signal: AbortSignal

  #### Returns Promise<PaginatedResponse<TwinFileGet>>

  #### Throws

  On invalid query parameters (400).

  Implementation of ITwinClient.listTwinFiles

### listTwinFileVersions

- listTwinFileVersions(
  twinId: string,
  fileId: string,
  options?: TwinFileVersionListOptions,
  signal?: AbortSignal,
  ): Promise<PaginatedResponse<TwinFileGet>>

  #### Parameters

  - twinId: string
  - fileId: string
  - `Optional` options: TwinFileVersionListOptions
  - `Optional` signal: AbortSignal

  #### Returns Promise<PaginatedResponse<TwinFileGet>>

  #### Throws

  On invalid query parameters (400).

  Implementation of ITwinClient.listTwinFileVersions

### listTwins

- listTwins(
  relatedTo?: string,
  page?: string,
  limit?: number,
  signal?: AbortSignal,
  ): Promise<PaginatedResponse<ListTwinItem>>

  #### Parameters

  - `Optional` relatedTo: string

    Filter twins by container ID.

  - `Optional` page: string
  - `Optional` limit: number
  - `Optional` signal: AbortSignal

  #### Returns Promise<PaginatedResponse<ListTwinItem>>

  #### Throws

  On invalid query parameters (400).

  Implementation of ITwinClient.listTwins

### listTwinVersions

- listTwinVersions(
  id: string,
  options?: {
  includeDeleted?: boolean;
  limit?: number;
  page: undefined | string;
  },
  signal?: AbortSignal,
  ): Promise<PaginatedResponse<ListTwinItem>>

  #### Parameters

  - id: string
  - `Optional` options: { includeDeleted?: boolean; limit?: number; page: undefined | string }
  - `Optional` signal: AbortSignal

  #### Returns Promise<PaginatedResponse<ListTwinItem>>

  #### Throws

  On invalid query parameters (400).

  Implementation of ITwinClient.listTwinVersions

### loadGeometryInfo

- loadGeometryInfo(
  twin: string | { id: string; version: number },
  signal?: AbortSignal,
  ): Promise<TwinGeometryInfo<T8GIMeshDescriptor, T8GIStyle, T8GIRegion>>

  Downloads and deserializes geometry info (t8gi) using default types. When no version is specified, searches versions newest-first for one containing t8gi content.

  #### Parameters

  - twin: string | { id: string; version: number }

    Twin ID string, or `{id, version}` to load a specific version.

  - `Optional` signal: AbortSignal

  #### Returns Promise<TwinGeometryInfo<T8GIMeshDescriptor, T8GIStyle, T8GIRegion>>

  #### Throws

  When no version has t8gi content.

  Implementation of ITwinClient.loadGeometryInfo

### loadGeometryInfoWithFactories

- loadGeometryInfoWithFactories<TMeshDescriptor, TStyle, TRegion>(
  twin: string | { id: string; version: number },
  meshDescriptorFactory: (dto: T8GIMeshDescriptorDTO) => TMeshDescriptor,
  styleFactory: (dto: T8GIStyleDTO) => TStyle,
  regionFactory: (dto: T8GIRegionDTO) => TRegion,
  signal?: AbortSignal,
  ): Promise<TwinGeometryInfo<TMeshDescriptor, TStyle, TRegion>>

  Downloads and deserializes geometry info (t8gi) using custom factory functions. When no version is specified, searches versions newest-first for one containing t8gi content.

  #### Type Parameters

  - TMeshDescriptor
  - TStyle
  - TRegion

  #### Parameters

  - twin: string | { id: string; version: number }

    Twin ID string, or `{id, version}` to load a specific version.

  - meshDescriptorFactory: (dto: T8GIMeshDescriptorDTO) => TMeshDescriptor
  - styleFactory: (dto: T8GIStyleDTO) => TStyle
  - regionFactory: (dto: T8GIRegionDTO) => TRegion
  - `Optional` signal: AbortSignal

  #### Returns Promise<TwinGeometryInfo<TMeshDescriptor, TStyle, TRegion>>

  #### Throws

  When no version has t8gi content.

  Implementation of ITwinClient.loadGeometryInfoWithFactories

### loadTwin

- loadTwin(
  twin: string | { id: string; version: number },
  signal?: AbortSignal,
  ): Promise<
  Twin<
  T8Project<T8Product<T8EntityType<T8Unit>, T8Unit>, T8Unit>,
  T8Product<T8EntityType<T8Unit>, T8Unit>,
  T8EntityType<T8Unit>,
  T8Unit,
  >,
  >

  Downloads and deserializes the T8 client model (t8cm + t8cm-ext) using default types. When no version is specified, searches versions newest-first for one containing t8cm content.

  #### Parameters

  - twin: string | { id: string; version: number }

    Twin ID string, or `{id, version}` to load a specific version.

  - `Optional` signal: AbortSignal

  #### Returns Promise<
  Twin<
  T8Project<T8Product<T8EntityType<T8Unit>, T8Unit>, T8Unit>,
  T8Product<T8EntityType<T8Unit>, T8Unit>,
  T8EntityType<T8Unit>,
  T8Unit,
  >,
  >

  #### Throws

  When no version has t8cm content.

  Implementation of ITwinClient.loadTwin

### loadTwinWithFactories

- loadTwinWithFactories<TProject, TProduct, TEntityType, TUnit>(
  twin: string | { id: string; version: number },
  projectFactory: (dto: T8ClientProjectDTO<TUnit>) => TProject,
  productFactory: (dto: T8ClientProductDTO<TUnit>) => TProduct,
  entityTypeFactory: (dto: T8ClientEntityTypeDTO<TUnit>) => TEntityType,
  unitFactory: (dto: T8ClientUnitDTO, dataModel: T8ClientModelDTO) => TUnit,
  connectProject: (
  dto: T8ClientProjectConnectionsDTO<TProduct>,
  project: TProject,
  ) => void,
  connectProduct: (
  dto: T8ClientProductConnectionsDTO<TProduct, TEntityType>,
  product: TProduct,
  ) => void,
  signal?: AbortSignal,
  ): Promise<Twin<TProject, TProduct, TEntityType, TUnit>>

  Downloads and deserializes the T8 client model using custom factory functions for domain-specific types. When no version is specified, searches versions newest-first for one containing t8cm content.

  #### Type Parameters

  - TProject
  - TProduct
  - TEntityType
  - TUnit

  #### Parameters

  - twin: string | { id: string; version: number }

    Twin ID string, or `{id, version}` to load a specific version.

  - projectFactory: (dto: T8ClientProjectDTO<TUnit>) => TProject
  - productFactory: (dto: T8ClientProductDTO<TUnit>) => TProduct
  - entityTypeFactory: (dto: T8ClientEntityTypeDTO<TUnit>) => TEntityType
  - unitFactory: (dto: T8ClientUnitDTO, dataModel: T8ClientModelDTO) => TUnit
  - connectProject: (dto: T8ClientProjectConnectionsDTO<TProduct>, project: TProject) => void
  - connectProduct: (
    dto: T8ClientProductConnectionsDTO<TProduct, TEntityType>,
    product: TProduct,
    ) => void
  - `Optional` signal: AbortSignal

  #### Returns Promise<Twin<TProject, TProduct, TEntityType, TUnit>>

  #### Throws

  When no version has t8cm content.

  Implementation of ITwinClient.loadTwinWithFactories

### loadTwinWithGeometry

- loadTwinWithGeometry(
  twin: string | { id: string; version: number },
  signal?: AbortSignal,
  ): Promise<
  Twin<
  T8ProjectWithGeometry,
  T8ProductWithGeometry<T8EntityType<T8Unit>>,
  T8EntityType<T8Unit>,
  T8Unit,
  >,
  >

  Downloads and deserializes both the client model (t8cm) and geometry (t8gi/t8gd) into a combined result. When no version is specified, searches versions newest-first for one containing both t8cm and t8gi content.

  #### Parameters

  - twin: string | { id: string; version: number }

    Twin ID string, or `{id, version}` to load a specific version.

  - `Optional` signal: AbortSignal

  #### Returns Promise<
  Twin<
  T8ProjectWithGeometry,
  T8ProductWithGeometry<T8EntityType<T8Unit>>,
  T8EntityType<T8Unit>,
  T8Unit,
  >,
  >

  #### Throws

  When no version has both t8cm and t8gi content.

  Implementation of ITwinClient.loadTwinWithGeometry

### restoreAsset

- restoreAsset(twinId: string, assetId: string, etag: string): Promise<AssetGet>

  #### Parameters

  - twinId: string
  - assetId: string
  - etag: string

  #### Returns Promise<AssetGet>

  #### Throws

  When the asset does not exist (404).

  #### Throws

  On etag mismatch (409). The error's `currentAsset` contains the server's current state.

  Implementation of ITwinClient.restoreAsset

### restoreTwin

- restoreTwin(
  twinId: string,
  etag: string,
  signal?: AbortSignal,
  ): Promise<TwinGet>

  #### Parameters

  - twinId: string
  - etag: string
  - `Optional` signal: AbortSignal

  #### Returns Promise<TwinGet>

  #### Throws

  When the twin does not exist (404).

  #### Throws

  On etag mismatch (409). The error's `currentTwin` contains the server's current state.

  Implementation of ITwinClient.restoreTwin

### restoreTwinFile

- restoreTwinFile(
  twinId: string,
  fileId: string,
  etag: string,
  signal?: AbortSignal,
  ): Promise<TwinFileGet>

  #### Parameters

  - twinId: string
  - fileId: string
  - etag: string
  - `Optional` signal: AbortSignal

  #### Returns Promise<TwinFileGet>

  #### Throws

  When the file does not exist (404).

  #### Throws

  On etag mismatch (409). The error's `currentTwinFile` contains the server's current state.

  #### Throws

  On invalid request (400).

  Implementation of ITwinClient.restoreTwinFile

### updateAsset

- updateAsset(
  twinId: string,
  assetId: string,
  asset: AssetPut,
  signal?: AbortSignal,
  ): Promise<AssetGet>

  #### Parameters

  - twinId: string
  - assetId: string
  - asset: AssetPut
  - `Optional` signal: AbortSignal

  #### Returns Promise<AssetGet>

  #### Throws

  On invalid request body (400). The error's `errorBody` has structured detail.

  #### Throws

  On etag mismatch (409). The error's `currentAsset` contains the server's current state.

  Implementation of ITwinClient.updateAsset

### updateTwin

- updateTwin(
  twinId: string,
  twin: TwinPut,
  signal?: AbortSignal,
  ): Promise<TwinGet>

  Alias for createOrUpdateTwin.

  #### Parameters

  - twinId: string
  - twin: TwinPut
  - `Optional` signal: AbortSignal

  #### Returns Promise<TwinGet>

  Implementation of ITwinClient.updateTwin