Java SDK
The 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.
The Java SDK is generated from the OpenAPI document: one API class per group of operations, one method per operation, and a model class per request and response. It talks to the server with the JDK's own java.net.http client. The classic Java SDK (nl.bimbase.bimworks:client) is a different, hand-written client; the two can be used side by side.
Artifact#
| Coordinates | nl.bimbase.bimworks:sdk, version equal to your BIM.works server |
| Repository | https://maven.bim.works/artifactory/BIM.works, with the credentials of Java |
| Java | 17 or later |
| Packages | nl.bimbase.bimworks.sdk.api (the API classes), nl.bimbase.bimworks.sdk.model (the models), nl.bimbase.bimworks.sdk.client (ApiClient, ApiException) |
| Dependencies | Jackson (jackson-databind, jackson-datatype-jsr310, jackson-databind-nullable) |
<dependency>
<groupId>nl.bimbase.bimworks</groupId>
<artifactId>sdk</artifactId>
<version>3.0.0-beta.192</version>
</dependency>Connect and log in#
An ApiClient holds the address of your instance's OpenAPI root (BIM_WORKS_ADDRESS/openapi); every API class is made from it. The login, LoginWithApiToken with your API token, answers an AuthResult whose getAuth().getBase64() is the auth token. The SDK has no bearer setting of its own, so the client's request interceptor puts the token on every request. An API object copies the client's settings when it is made, so set the interceptor before you make the API objects of your calls, as the examples do.
import nl.bimbase.bimworks.sdk.api.AuthApi;
import nl.bimbase.bimworks.sdk.api.FsApi;
import nl.bimbase.bimworks.sdk.client.ApiClient;
import nl.bimbase.bimworks.sdk.model.Auth;
import nl.bimbase.bimworks.sdk.model.LoginWithApiTokenRequest;
public class Example {
public static void main(String[] args) throws Exception {
// 1. Connect to BIM.works and log in with your API token
ApiClient client = new ApiClient();
client.updateBaseUri("https://bim.works/openapi");
Auth auth = new AuthApi(client)
.loginWithApiToken(new LoginWithApiTokenRequest().token("<your API token>"))
.getAuth();
client.setRequestInterceptor(builder -> builder.setHeader("Authorization", "Bearer " + auth.getBase64()));
// 2. The request
// (GetRootNodeUuid takes no request)
// 3. The call
var result = new FsApi(client).getRootNodeUuid();
// 4. The result
System.out.println(client.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(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):
- Connect — the client, logged in as above. An operation that needs no login (the logins, GetApplicationVersion) skips the login.
- The request —
client.getObjectMapper().readValue(json, <Model>.class)makes the request from the JSON with the wire names that the operation's page shows, in a text block. Multipart operations take their form fields as arguments instead. - The call —
new <Api>(client).<method>(request). - The result — printed as JSON with the wire names by the same mapper; a file is moved into place, and a call without a result prints
Done.
So the same JSON goes into every language, and copying an example is enough once the artifact is on your class path. With several calls, keep one client and repeat steps 2 to 4. In a text block the JSON's own backslashes are doubled (\\"), as the examples do.
Classes#
In code, a model also has typed getters and setters and fluent setters (new QueryRequest().query("GET qid")). Reading JSON is lenient: a misspelled key is dropped, and a model item with a wrong type becomes null, so use the names on the models page. A request also sends the defaults of the properties it does not set; they are the server's own defaults.
Errors#
A call that the server answers with an error status throws nl.bimbase.bimworks.sdk.client.ApiException: getCode() is the HTTP status and getResponseBody() the server's error as JSON (Errors). Every example declares throws Exception, so a failure ends the program with the status and the error.
try {
new IfcApi(client).query(request);
} catch (ApiException e) {
System.err.println(e.getCode() + " " + e.getResponseBody());
}Files#
- Downloads return a
File: the SDK writes the body to a temporary file that is deleted when the JVM exits, so the examples move it into place withFiles.move. - Uploads take a
File. The multipart methods take every form field as an argument, in the order of the operation's page; passnullfor the fields you leave out. The text fields are sent as ISO-8859-1, so give a file name outside Latin-1 in ASCII. - UploadModel with
wait_mscan answer202with the checkin's status, which the method cannot read: withoutwait_msit waits for the version.
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.