How-to guide·AuthenticationJavaScript · Java · .NET

Create an API token

Create a long-lived, revocable API token on a folder, in the UI or with the CreateApiToken call, and store its secret.

For anyone who needs a credential for a backend, a script or a CI job. An API token belongs to the account that creates it, is rooted at one node (normally a folder), carries a set of scopes, expires on a date you choose and can be deleted at any time. The secret is shown exactly once.

Before you start#

  • An account login (in the UI, or LoginWithUsernamePassword for the API route) with write rights on the folder. Only an account creates API tokens: another API token, whatever its scopes, cannot, and neither can a versions, nodes, recursive-node, anonymous or workspace token; the server answers CREDENTIAL_CREATION_NOT_ALLOWED.
  • The folder the token is for. One token per application (or per environment of it) is the usual layout: everything the application does is chrooted to that folder.
  • The scopes the application needs, no more. Read Tokens and delegation for the catalogue; a scope you do not hold yourself cannot be granted.

1. In the UI#

  1. Open the properties of the folder (the node popup) and choose the API Tokens section. It is shown in the developer UI mode; a token can also be created on a single model node, which then grants exactly that model and nothing else.

  2. Click Add and fill in the form:

    Field Meaning
    Name Only for finding the token back in the list.
    Expires on The day the token stops working, usable through the whole of that UTC day. One month ahead unless you pick another; never further than the instance maximum (three years by default). Reminders go out 7, 3 and 1 days before.
    BIM context How uploads through this token are interpreted; fixed at creation.
    Only allow certain CORS domains With the list of browser origins for the token. The list only counts on an instance whose web_security.cors setting is REQUIRED: there a browser origin is let in only when an active API token lists it, and this token is refused from origins not on its list. The default setting, WILDCARD, accepts every origin.
    Only allow white-listed IP addresses With the list of addresses (for example your application server's). Off means no IP restriction.
    Scopes The grouped scope picker; at least one scope is required.
  3. Click Create. The next screen shows the secret (BAT- followed by 40 hex characters) with a copy button. Copy it now: the server stores only a hash and the last four characters, and never shows it again.

The list on the same section shows every token of the folder with its expiry, restrictions, scopes and last login, and offers Edit (name, expiry, restrictions, scopes), Rotate secret (a new secret, same token) and Delete. The end-user walkthrough with screenshots is Manage API tokens.

2. With the API#

The operation is CreateApiToken. It answers the secret once, as {token, expires_on}:

POST/openapi/auth/CreateApiTokenCreateApiToken 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/auth/CreateApiToken" \
  -H "Authorization: Bearer $BIMWORKS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "node_uuid": "<folder uuid>",
  "name": "Nightly export",
  "scopes": ["fs:read", "model:read", "query:run"],
  "expires_on": "2027-12-31"
}'
Send to see the response

The fields:

Field Required Meaning
name yes A label.
node_uuid yes The node the token is rooted at; you need write rights on it.
scopes yes Scope names (fs:read, …); at most your own scopes.
expires_on no A YYYY-MM-DD day (the end of that UTC day) or an ISO date-time. Default: the instance's default span ahead, one month; maximum: three years.
cors_enabled_domains, only_cors_enabled_addresses no The origin allow-list, which counts only when the instance's web_security.cors is REQUIRED, and a flag that is stored and shown but not enforced.
white_listed_ip_addresses, only_white_listed_ip_addresses no The IP allow-list and whether it is enforced.
bim_context no The BIM context for uploads; DEFAULT when absent.

The Java and .NET SDKs wrap the same call:

import java.time.LocalDate;
import java.util.EnumSet;
import com.fasterxml.jackson.databind.node.ObjectNode;
import nl.bimbase.bimworks.client.Scope;

ObjectNode result = client.admin.createApiToken(folderUuid, "Nightly export",
		EnumSet.of(Scope.FS_READ, Scope.MODEL_READ, Scope.QUERY_RUN), LocalDate.of(2027, 12, 31));
String token = result.get("token").asText();       // store it now
String expiresOn = result.get("expires_on").asText();
string token = client.Admin.CreateApiToken(folderUuid, "Nightly export",
    new HashSet<Scope> { Scope.FS_READ, Scope.MODEL_READ, Scope.QUERY_RUN }, new DateTime(2027, 12, 31));   // store it now

The Java method is AdminApi.createApiToken (AdminApi); the .NET one, Admin.CreateApiToken (Admin), returns the token only (the expiry is the day you passed, or the default when you pass none).

3. Store the secret#

Treat the secret like a password: an environment variable or a secret store, never a repository or a web page. A leaked token is deleted or rotated in the UI, which invalidates every auth token that was obtained with it on the next request.

Check#

Log in with the new token and ask for its root node (Log in with an API token); the UUID equals the folder you created the token on. A wrong or already deleted secret fails with INVALID_API_TOKEN or API_TOKEN_DELETED, a token past its date with API_TOKEN_EXPIRED.