---
title: Java quick start
summary: Add the client to a Maven project, log in with an API token, list your tree, upload a model and query it, in one program.
order: 40
languages: [java]
terms: [api-token, node, version, qid, bql]
see-also: [how-to/install/java, how-to/auth/log-in-with-an-api-token, how-to/models/upload-a-model, how-to/query/run-a-bql-query, reference/java]
featured: true
---

# Java quick start

```note title="Classic SDK"
This tutorial uses the classic, hand-written Java [[term:sdk|SDK]]. For a new integration, the [[page:reference/sdk/java|Java SDK]] generated from the OpenAPI document is the choice; its reference has a complete example for every operation ([[page:reference/sdk]] compares the two).
```

The Java client talks to BIM.works over its own transport (HTTP by default, HTTP/2 where the server offers it over HTTPS; WebSocket only when you pass `new ClientSettings(ConnectionType.WEB_SOCKET)` to the factory), not over the OpenAPI, and covers the whole API. This page takes you from an empty Maven project to a program that uploads a model and queries it. Java 17 or later is required.

## Install

The client is `nl.bimbase.bimworks:client`, published on the BIM.works Maven repository, which needs the credentials your BIM.works contact gives you. Use the version of your server (the version pill at the top of this page is the server's).

```xml {#pom}
<dependencies>
    <dependency>
        <groupId>nl.bimbase.bimworks</groupId>
        <artifactId>client</artifactId>
        <version>3.0.0-beta.192</version>
    </dependency>
</dependencies>
<repositories>
    <repository>
        <id>BIM.works</id>
        <url>https://maven.bim.works/artifactory/BIM.works</url>
    </repository>
</repositories>
```

The credentials go in `~/.m2/settings.xml` under a `<server>` with the same id. When the client's Jetty clashes with your own, use `clientshaded` instead, which relocates it; it does not relocate Jackson or Guava. [[page:how-to/install/java]] has the details, the Gradle form and the legacy client.

## Log in

```example
name: java-quick-start
code: java/quick-start.java
notes: |
  One `BimWorksClientFactory` per instance and one `BimWorksClient` per login; both are `AutoCloseable`, so the try-with-resources closes the connection when the program ends. The upload waits until the server has stored the file and created the version, so the query on the next line finds a fully indexed model.
highlight: 21-22,28-30,34-36,41-45
```

`factory.createClientWithApiToken(token)` logs in and returns a client, or throws `BimWorksException` with an error code (`AuthenticationError.INVALID_API_TOKEN` and friends) when it cannot. The client can be as short- or long-lived as you need; the sub-APIs (`client.fs`, `client.upload`, `client.bim`, `client.tokens`, `client.modelChecks`, `client.gis`, …) are fields on it. `client.getApplicationVersion()` returns the server version as JSON and is a good first call to confirm the address.

## List the tree

`client.fs.getRootNodeUuid()` is the node your token was created on; every path is relative to it, so `client.fs.getNodeByPath("/")` is the same node as a `TreeNode`. `client.fs.listNodes(uuid, false)` returns the children in a `nodes` array of JSON objects (the `false` leaves deleted nodes out); a node that holds a model has `last_version_uuid`. `createNode(parentUuid, name, isFolder)` adds a folder or an empty model node; `createNodeIfNotExists` does the same without failing when the name is taken.

## Upload

`client.upload.uploadModel(new UploadBuilder(nodeUuid).fromPath(path))` uploads a file into a folder node; a new model node named after the file is created in it, or a new version when a model with that name exists. The builder also takes a `File`, an `InputStream` with its size, a `byte[]`, or a URL the server downloads itself (`urlPassThrough`, for files on S3 or Azure), and options such as `forceReprocessing`, `validationLevel` and a `progressListener`. The call blocks until the server has processed the upload and returns an `UploadModelResponse`; `getNewVersionUuid()` is the version to query and view. A duplicate file is detected by hash and not transferred again.

## Query

`client.bim.query(bql, versionUuid...)` runs a [[term:bql|BQL]] statement and returns the rows as a Jackson `ArrayNode`, one object per row, with every feature under its path and every value wrapped in an object with a `value` field (and a `unit` when it has one). `client.bim.queryCount(bql, Set.of(versionUuid))` returns only the number of matching objects, `client.bim.queryQids(bql, versions)` only their qids, and `client.bim.validate(bql)` tells you whether the server accepts a query without running it. The [BQL course](../bql/index.md) teaches the language.

## Where to go from here

The same client runs checks (`client.modelChecks.runChecks`, `runIdsCheck`), downloads BCF (`client.modelChecks.downloadCheckResultsAsBcf`), mints tokens for browsers (`client.tokens.createVersionsToken`), reads and writes geo references (`client.gis`) and exports IFC, glTF and CityGML. The [[page:reference/java|Java reference]] lists every type; the how-to guides show one task at a time, starting with [[page:how-to/models/upload-a-model]] and [[page:how-to/query/run-a-bql-query]].
