TypeScript SDK

The TypeScript and JavaScript SDK generated from the OpenAPI document (npm @bimworks/sdk) — installation, connecting and logging in, the four steps of every example, the API classes and models, errors, files and uploads.

The TypeScript SDK is generated from the OpenAPI document: one API class per group of operations, one method per operation, and an interface per request and response. It is written in TypeScript and runs as JavaScript too, in Node.js and in browsers, over fetch. A page with the 3D or 2D viewer uses the classic JavaScript SDK instead, which the viewers take.

Package#

Package @bimworks/sdk on https://npm.bim.works, version equal to your BIM.works server
Runtime Node.js 20 or later (global fetch, FormData and File), or a current browser
TypeScript 5 or later; the package ships its .d.ts files
Module One package; import every class and function from @bimworks/sdk
Text#
@bimworks:registry=https://npm.bim.works
Shell#
npm install @bimworks/sdk@3.0.0-beta.192

The registry needs your company credentials (JavaScript and TypeScript). The examples are ES modules with top-level await: give your package.json "type": "module". To type-check them, use a tsconfig.json with "lib": ["es2022", "dom"] (the package's types name fetch types from the DOM library) and, on Node.js, "types": ["node"].

Connect and log in#

A Configuration holds the address of your instance's OpenAPI root (BIM_WORKS_ADDRESS/openapi) and the bearer token. The login, LoginWithApiToken with your API token, answers an AuthResult: the Auth object, whose base64 is the auth token, or that token alone when you ask for response_format: "base64". A Configuration cannot change, so the login uses one without a token and the client one with it; every API class is made from that client.

OpenAPI SDK
import { AuthApi, Configuration, FsApi } from "@bimworks/sdk";

// 1. Connect to BIM.works and log in with your API token
const basePath = "https://bim.works/openapi";
const auth = await new AuthApi(new Configuration({ basePath }))
  .loginWithApiToken({ loginWithApiTokenRequest: { token: "<your API token>" } });
const client = new Configuration({ basePath, accessToken: typeof auth === "string" ? auth : auth.base64 });

// 2. The request
// (GetRootNodeUuid takes no request)

// 3. The call
const result = await new FsApi(client).getRootNodeUuid();

// 4. The result
console.log(result);

Every example in four steps#

Every example on these pages and on the operation pages of the API part is a complete program in the same four steps (reference/sdk#example-shape):

  1. Connect — the client, logged in as above. An operation that needs no login (the logins, GetApplicationVersion) skips the login.
  2. The request — <Model>FromJSON(json) makes the request from the JSON with the wire names that the operation's page shows. Multipart operations take their form fields as one object instead.
  3. The call — await new <Api>(client).<method>({ <request parameter>: request }).
  4. The result — <Model>ToJSON(result) turns a result back into the JSON with the wire names, which the example prints; a file is written to disk, and a call without a result prints Done.

So the same JSON goes into every language, and copying an example is enough once the package is installed. With several calls, keep one client and repeat steps 2 to 4.

Classes#

ClassGroupMethods
ActionsApiActionsaddAction, deleteAction, getAction, listActions, undeleteAction, updateAction
LinkedDataApiLinked dataaddLinkTargets, confirmLinkMatch, deleteLinkedData, downloadLinkedData, endLink, getLinkedData, getLinkedDataCounts, getLinkedDataPolicy, linkData, listLinkedData, reattachLink, replaceLinkedData, restoreLinkedData, unlinkData, updateLinkedData
ModelApiModeladdModelWithUrl, augmentBcf, download, downloadIfcXml, exportGeometry, exportVectorSvg, getCheckin, getValidationReport, lookupModelHashes, render, schemaConversionReport, uploadModel
AccountApiAccountchangePassword, getSettings, listReferenceValues, logout, register, requestPasswordReset, requestValidationEmail, saveSettings, signOutOtherSessions, validateEmailAddress
IFCApiIFC - Industry Foundation Classescheck, commitTransaction, compareModels, compareObjects, deleteComparePairOverride, exportCompareResult, getCompareBul, getCompareResult, getMatchCandidates, getObjectHistory, getVersionChanges, listBuildingStoreys, listComparePairOverrides, mapQids, parseQuery, query, recordUploadAsTransaction, resolveBvl, setComparePairOverride, textSearch, upgradeSyntax
GISApiGIS - Geographic Information SystemscopyGeoReference, exportCityGML3, extractGeoReference, generate3DTilesUrl, getGeoReference, setGeoReference
AuthApiAuth - AuthenticationcreateAnonymousToken, createApiToken, createNodesToken, createRecursiveNodeToken, createVersionsToken, deleteApiToken, getSession, listApiTokens, loginAnonymous, loginWithAnonymousToken, loginWithApiToken, loginWithUsernamePassword, updateApiToken
FsApiFs - FileSystemcreateNode, deleteNode, deleteNodeError, deleteVersion, downloadAsZip, getNode, getRootNodeUuid, getVersion, listNodeErrors, listNodes, listNodesRecursive, listVersions, moveNode, undeleteNode, updateNode, updateVersion
WorkspacesApiWorkspacescreateWorkspace, deleteWorkspace, listWorkspaces, publishWorkspace, updateWorkspace
InfoApiInfogetApplicationVersion
ViewerApiViewergetGeometryMetaData
AdminApiAdminlistAccountUserFeatures, listAccounts, listOrganizations
AIApiAI - Artificial IntelligencetextToAction
VersionsApiVersionsversion
ModelsRequests and responses289 model classes

A model is an interface with camelCase properties (versionUuid); <Model>FromJSON and <Model>ToJSON convert between it and the wire's snake_case JSON. FromJSON reads only the names it knows: a misspelled key, an explicit null or a model item with a wrong type is left out of the request, so use the names on the models page.

Errors#

A call that the server answers with an error status throws a ResponseError; its response is the HTTP response, whose JSON is the server's error (Errors).

TypeScript#
import { ResponseError } from "@bimworks/sdk";

try {
  await new IFCApi(client).query({ queryRequest: request });
} catch (e) {
  if (e instanceof ResponseError) {
    console.error(e.response.status, await e.response.json());
  } else {
    throw e;
  }
}

Files#

  • Downloads return a Blob; the examples write it with writeFileSync(path, Buffer.from(await result.arrayBuffer())). For a large file, stream it instead: the …Raw variant of every method (downloadRaw) gives the Response, whose body you pipe to a file.
  • Uploads take a File: new File([await openAsBlob("model.ifc")], "model.ifc") reads the file lazily and gives the part its name, which the server uses as the model's name when no filename field is sent (a bare Blob would arrive as blob).
  • UploadModel with wait_ms can answer 202 with the checkin's status instead of the version; uploadModelRaw gives the status and the body to tell them apart.

Pages#

  • Java SDKThe Java SDK generated from the OpenAPI document (Maven nl.bimbase.bimworks:sdk) — the artifact, connecting and logging in, the four steps of every example, the API classes and models, errors, files and uploads.
  • .NET SDKThe .NET SDK generated from the OpenAPI document (NuGet BIMworks.Sdk) — the package, connecting and logging in, the four steps of every example, the API classes and models, responses and errors, files and uploads.
  • TypeScript SDKThe TypeScript and JavaScript SDK generated from the OpenAPI document (npm @bimworks/sdk) — installation, connecting and logging in, the four steps of every example, the API classes and models, errors, files and uploads.
  • PHP SDKThe PHP SDK generated from the OpenAPI document (Composer bimbase/bimworks) — the package, connecting and logging in, the four steps of every example, the API classes and models, errors, files and uploads.
  • Python SDKThe Python SDK generated from the OpenAPI document (bimworks on the BIM.works Python index) — the package, connecting and logging in, the four steps of every example, the API classes and models, errors, files and uploads.