Tutorial·Your first API calls

Getting started

Find the API, exchange an API token for an auth token, list the tree, query a model and download an original file, with curl.

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#
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#
curl "$BIMWORKS_URL/openapi.yml" | head -20

The same document drives the Swagger UI of the instance and the reference pages of this site, which are generated from it.

2. Log in#

All other calls want an auth token in the Authorization header. You get one by exchanging your API token with LoginWithApiToken; the API token itself never goes into any other request.

POST/openapi/auth/LoginWithApiTokenLoginWithApiToken reference
Authorization
Bearer <auth token>
Content-Type
application/json
Body
1 2 3 4
Authorization: Bearer <auth token>
Content-Type: application/json
Accept: application/json
curl -X POST "$BIMWORKS_URL/openapi/auth/LoginWithApiToken" \
  -H "Authorization: Bearer $BIMWORKS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "token": "BIM_WORKS_API_TOKEN",
  "response_format": "base64"
}'
Send to see the response

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. 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:

POST/openapi/fs/ListNodesListNodes reference
Authorization
Bearer <auth token>
Content-Type
application/json
Body
1 2 3 4
Authorization: Bearer <auth token>
Content-Type: application/json
Accept: application/json
curl -X POST "$BIMWORKS_URL/openapi/fs/ListNodes" \
  -H "Authorization: Bearer $BIMWORKS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "path": "/"
}'
Send to see the response

The response is an array of nodes. A folder has "folder": true; a model node has last_version_uuid, the 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". List the tree has the complete walk.

4. Query a model#

Query runs a BQL statement on one or more models. A model is identified by its version UUID:

POST/openapi/ifc/QueryQuery reference
Authorization
Bearer <auth token>
Content-Type
application/json
Body
1 2 3 4 5 6
Authorization: Bearer <auth token>
Content-Type: application/json
Accept: application/json
curl -X POST "$BIMWORKS_URL/openapi/ifc/Query" \
  -H "Authorization: Bearer $BIMWORKS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "models": [
    {"type": "VersionModelIdentifier", "uuid": "BIM_WORKS_FIRST_MODEL"}
  ],
  "query": "GET qid, type, attribute.Name, quantity.*.Height UNIT m WHERE type = IFCDOOR LIMIT 5"
}'
Send to see the response

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#
[
  {
    "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 (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 Error codes.

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:

GET/openapi/Versions/{uuid}Version reference
Authorization
Bearer <auth token>
uuidpath
Authorization: Bearer <auth token>
Accept: */*
curl -X GET "$BIMWORKS_URL/openapi/Versions/{uuid}" \
  -H "Authorization: Bearer $BIMWORKS_TOKEN" \
  -OJ
Send to see the response

-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: UploadModel adds a model to a node as multipart/form-data (Upload a model), CreateVersionsToken mints a token that can only see the versions you name (the pattern for browsers, Tokens and delegation), Check runs an IDS or BCL check, and CommitTransaction writes changes back as a new version. Every operation has a page in the 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.