---
title: Getting started
summary: Find the API, exchange an API token for an auth token, list the tree, query a model and download an original file, with curl.
order: 10
terms: [api-token, auth-token, node, version, qid, bql]
see-also: [api, how-to/auth/log-in-with-an-api-token, how-to/models/upload-a-model, how-to/query/run-a-bql-query, tutorials/bql/index]
---

# Getting started

Every call in this lesson is an HTTP request to your BIM.works instance. Press Send in a block to run it against this instance with your demo token, or copy the snippet tab into a shell; the snippets keep the instance address and the token in two variables, so you set them once.

```shell {#setup}
BIMWORKS_URL=https://bim.works
```

## 1. Find the API

The API lives under `<instance>/openapi`, and the instance publishes its own description at `<instance>/openapi.yml` (also `.json`). This request needs no token and is the quickest way to confirm the address and the version of the API you are talking to:

```shell {#spec}
curl "$BIMWORKS_URL/openapi.yml" | head -20
```

The same document drives the Swagger UI of the instance and the [[page:api|reference pages]] of this site, which are generated from it.

## 2. Log in

All other calls want an [[term:auth-token|auth token]] in the `Authorization` header. You get one by exchanging your [[term:api-token|API token]] with `LoginWithApiToken`; the API token itself never goes into any other request.

```try-it {#try-login}
operation: LoginWithApiToken
method: POST
path: /openapi/auth/LoginWithApiToken
body: |
  {
    "token": "BIM_WORKS_API_TOKEN",
    "response_format": "base64"
  }
```

With `response_format` set to `base64` the response body is one string: the auth token, ready to be sent as `Authorization: Bearer <token>` (in the snippets, `$BIMWORKS_TOKEN`). Without it the response is the full `Auth` object, whose `base64` field holds the same string next to the signed payload it encodes. Either way the token is valid for at most 90 days (the instance's `api_token_validity`) and never longer than the API token it was made from; when it expires, log in again. [[page:explanation/tokens-and-delegation]] explains what the token contains and how to hand out narrower tokens to browsers.

## 3. Your tree

A token sees the node it was created on as its root. `GetRootNodeUuid` returns that node's UUID; `ListNodes` lists the children of a node by UUID or by path, and paths are relative to your root, so `"/"` is the root itself:

```try-it {#try-list-nodes}
operation: ListNodes
method: POST
path: /openapi/fs/ListNodes
body: |
  {
    "path": "/"
  }
```

The response is an array of [[term:node|nodes]]. A folder has `"folder": true`; a model node has `last_version_uuid`, the [[term:version]] you query, view and download, and `last_version` with that version's details. Walk down with `ListNodes` on a child's `uuid`, or jump straight to a node with `GetNode` and a path such as `"/Demo/Schependomlaan/IFC Schependomlaan.ifc"`. [[page:how-to/models/list-the-tree]] has the complete walk.

## 4. Query a model

`Query` runs a [[term:bql|BQL]] statement on one or more models. A model is identified by its version UUID:

```try-it {#try-query}
operation: Query
method: POST
path: /openapi/ifc/Query
body: |
  {
    "models": [
      {"type": "VersionModelIdentifier", "uuid": "BIM_WORKS_FIRST_MODEL"}
    ],
    "query": "GET qid, type, attribute.Name, quantity.*.Height UNIT m WHERE type = IFCDOOR LIMIT 5"
  }
```

`models` may also hold a `NodeModelIdentifier` (a node, optionally `recursive`); an empty `models` array validates the query without running it and answers its `messages`. Add `"format": "ifc"` or `"ifcxml"` and the same call returns the matching objects as an IFC or ifcXML model instead of JSON; `count`, `qids`, `csv` and `xlsx` are the other formats.

## 5. Read the response

The JSON result is an array with one object per row. Each feature the `GET` asked for appears under its path, and every value is wrapped in an object, so a value that carries a unit can say so:

```json {#response}
[
  {
    "qid": "8c2232c0-e521-4ed9-b48b-d9e1acf44427-63563",
    "type": "IFCDOOR",
    "attribute": {"Name": {"value": "stelkozijn"}},
    "quantity": {"BaseQuantities": {"Height": {"value": 2.315, "unit": "m"}}}
  }
]
```

`qid` is the version UUID and the object id joined by a hyphen, the same identifier the viewers and the SDKs use ([[term:qid]]). Wildcards are resolved: `quantity.*.Height` comes back under the set that actually held the value. A value that has a unit says which one, in the unit you asked for. Grouped queries return one row per group with the aggregates under their function name (`COUNT`, `SUM`, …) or their alias. The `compression` request field switches to a compact form where version UUIDs and types are listed once and referenced by index; leave it at its default unless response size is a problem.

Errors come back with an HTTP status and an `ErrorResponse` body: `400` for a query the server rejects (the `message` says where), `401` for a missing or expired token, `403` when the token lacks the operation's scope (`query:run` here). The codes and their meaning are listed in [[page:reference/errors]].

## 6. Download the original file

Every version keeps the file it was created from. `Version` is a plain `GET`, so the URL doubles as a download link:

```try-it {#try-version}
operation: Version
method: GET
path: /openapi/Versions/{uuid}
binary: true
```

`-OJ` lets `curl` take the file name from the response. `Download` is the `POST` variant with a model identifier in the body, and `DownloadAsZip` packs a whole folder.

## Where to go from here

You have logged in, found a model, queried it and downloaded it. The remaining operations follow the same pattern: [[openapi:UploadModel]] adds a model to a node as `multipart/form-data` ([[page:how-to/models/upload-a-model]]), [[openapi:CreateVersionsToken]] mints a token that can only see the versions you name (the pattern for browsers, [[page:explanation/tokens-and-delegation]]), [[openapi:Check]] runs an IDS or BCL check, and [[openapi:CommitTransaction]] writes changes back as a new version. Every operation has a page in the [[page:api|reference]], with its request and response schemas and a try-it panel of its own. To learn the query language, follow [Learn BQL by doing](../bql/index.md).
