.NET SDK

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

The .NET SDK is generated from the OpenAPI document: one API interface per group of operations, one asynchronous method per operation, and a model class per request and response. It is built on Microsoft.Extensions.DependencyInjection and HttpClient. The classic .NET SDK (BIM.works_SDK) is a different, hand-written client; the two can be used side by side.

Package#

Package BIMworks.Sdk on nuget.org, version equal to your BIM.works server
Targets .NET 8 and .NET Standard 2.0; the examples need the .NET 8 SDK (C# 11 raw string literals)
Namespaces BIMworks.Sdk.Api (the API interfaces), BIMworks.Sdk.Model (the models), BIMworks.Sdk.Client and BIMworks.Sdk.Extensions (the setup)
Dependencies Microsoft.Extensions.Hosting, .Http and .Http.Polly, which come with the package
XML#
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="BIMworks.Sdk" Version="3.0.0-beta.192" />
  </ItemGroup>
</Project>

dotnet new console, dotnet add package BIMworks.Sdk, an example in Program.cs, and dotnet run.

Connect and log in#

The SDK's services.AddApi(...) registers the API interfaces, the bearer token and the HttpClient with the address of your instance's OpenAPI root (BIM_WORKS_ADDRESS/openapi). The SDK reads its tokens once, when the first API is made, so the examples make the services twice: once without a token for the login, LoginWithApiToken with your API token, and once with the auth token it answers (auth.Base64). The timeout is switched off: an upload waits for its checkin, which takes longer than HttpClient's default 100 seconds.

using System.Text.Json;
using BIMworks.Sdk.Api;
using BIMworks.Sdk.Client;
using BIMworks.Sdk.Extensions;
using BIMworks.Sdk.Model;
using Microsoft.Extensions.DependencyInjection;

// 1. Connect to BIM.works and log in with your API token
IServiceProvider Connect(string bearer)
{
    var services = new ServiceCollection();
    services.AddApi(options =>
    {
        options.AddTokens(new BearerToken(bearer));
        options.AddApiHttpClients(http =>
        {
            http.BaseAddress = new Uri("https://bim.works" + "/openapi");
            http.Timeout = Timeout.InfiniteTimeSpan;
        });
    });
    return services.BuildServiceProvider();
}
var login = await Connect("").GetRequiredService<IAuthApi>().LoginWithApiTokenAsync(new LoginWithApiTokenRequest("<your API token>"));
var auth = login.Ok()?.Auth ?? throw new HttpRequestException(login.RawContent, null, login.StatusCode);
var client = Connect(auth.Base64);
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;

// 2. The request
// (GetRootNodeUuid takes no request)

// 3. The call
var response = await client.GetRequiredService<IFsApi>().GetRootNodeUuidAsync();

// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result, json));

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

  1. Connect — the services, logged in as above, and the SDK's JSON options (JsonSerializerOptionsProvider). An operation that needs no login (the logins, GetApplicationVersion) skips the login.
  2. The request — JsonSerializer.Deserialize<Model>(json, options) makes the request from the JSON with the wire names that the operation's page shows, in a raw string literal. Multipart operations take their form fields as named arguments instead.
  3. The call — client.GetRequiredService<IApi>().MethodAsync(request).
  4. The result — response.Ok(), printed as JSON with the wire names; a file is written to disk, and a call without a result prints Done.

So the same JSON goes into every language, and copying an example is enough once the package is installed. With several calls, keep one client and repeat steps 2 to 4.

Classes#

ClassGroupMethods
ActionsApiActionsAddActionAsync, DeleteActionAsync, GetActionAsync, ListActionsAsync, UndeleteActionAsync, UpdateActionAsync
LinkedDataApiLinked dataAddLinkTargetsAsync, ConfirmLinkMatchAsync, DeleteLinkedDataAsync, DownloadLinkedDataAsync, EndLinkAsync, GetLinkedDataAsync, GetLinkedDataCountsAsync, GetLinkedDataPolicyAsync, LinkDataAsync, ListLinkedDataAsync, ReattachLinkAsync, ReplaceLinkedDataAsync, RestoreLinkedDataAsync, UnlinkDataAsync, UpdateLinkedDataAsync
ModelApiModelAddModelWithUrlAsync, AugmentBcfAsync, DownloadAsync, DownloadIfcXmlAsync, ExportGeometryAsync, ExportVectorSvgAsync, GetCheckinAsync, GetValidationReportAsync, LookupModelHashesAsync, RenderAsync, SchemaConversionReportAsync, UploadModelAsync
AccountApiAccountChangePasswordAsync, GetSettingsAsync, ListReferenceValuesAsync, LogoutAsync, RegisterAsync, RequestPasswordResetAsync, RequestValidationEmailAsync, SaveSettingsAsync, SignOutOtherSessionsAsync, ValidateEmailAddressAsync
IFCApiIFC - Industry Foundation ClassesCheckAsync, CommitTransactionAsync, CompareModelsAsync, CompareObjectsAsync, DeleteComparePairOverrideAsync, ExportCompareResultAsync, GetCompareBulAsync, GetCompareResultAsync, GetMatchCandidatesAsync, GetObjectHistoryAsync, GetVersionChangesAsync, ListBuildingStoreysAsync, ListComparePairOverridesAsync, MapQidsAsync, ParseQueryAsync, QueryAsync, RecordUploadAsTransactionAsync, ResolveBvlAsync, SetComparePairOverrideAsync, TextSearchAsync, UpgradeSyntaxAsync
GISApiGIS - Geographic Information SystemsCopyGeoReferenceAsync, ExportCityGML3Async, ExtractGeoReferenceAsync, Generate3DTilesUrlAsync, GetGeoReferenceAsync, SetGeoReferenceAsync
AuthApiAuth - AuthenticationCreateAnonymousTokenAsync, CreateApiTokenAsync, CreateNodesTokenAsync, CreateRecursiveNodeTokenAsync, CreateVersionsTokenAsync, DeleteApiTokenAsync, GetSessionAsync, ListApiTokensAsync, LoginAnonymousAsync, LoginWithAnonymousTokenAsync, LoginWithApiTokenAsync, LoginWithUsernamePasswordAsync, UpdateApiTokenAsync
FsApiFs - FileSystemCreateNodeAsync, DeleteNodeAsync, DeleteNodeErrorAsync, DeleteVersionAsync, DownloadAsZipAsync, GetNodeAsync, GetRootNodeUuidAsync, GetVersionAsync, ListNodeErrorsAsync, ListNodesAsync, ListNodesRecursiveAsync, ListVersionsAsync, MoveNodeAsync, UndeleteNodeAsync, UpdateNodeAsync, UpdateVersionAsync
WorkspacesApiWorkspacesCreateWorkspaceAsync, DeleteWorkspaceAsync, ListWorkspacesAsync, PublishWorkspaceAsync, UpdateWorkspaceAsync
InfoApiInfoGetApplicationVersionAsync
ViewerApiViewerGetGeometryMetaDataAsync
AdminApiAdminListAccountUserFeaturesAsync, ListAccountsAsync, ListOrganizationsAsync
AIApiAI - Artificial IntelligenceTextToActionAsync
VersionsApiVersionsVersionAsync
ModelsRequests and responses289 model classes

An optional property is an Option<T>: set or absent, so a property you leave out is not sent. Reading JSON drops a key the model does not have, so use the names on the models page. The schema Action is the class BimAction, which does not collide with System.Action.

Responses and errors#

A method does not throw on an error status: it returns the response. Ok() is the result when the status is 200 and null otherwise; IsOk, StatusCode, RawContent (the server's text, for an error its JSON, Errors) and an accessor per status (BadRequest(), Unauthorized(), …) tell the rest. The examples turn a failure into an HttpRequestException with the server's error as its message:

.NET#
var response = await client.GetRequiredService<IIFCApi>().QueryAsync(request);
if (!response.IsOk)
{
    Console.Error.WriteLine($"{(int)response.StatusCode} {response.RawContent}");
}

An operation that answers without a body has no Ok(): check IsSuccessStatusCode. UploadModel and AddModelWithUrl with wait_ms, CompareModels and GetCompareResult can answer 202: IsAccepted and Accepted() give that answer.

Files#

  • Downloads give a Stream with the whole file in memory; the examples copy it to a file.
  • Uploads take a FileParameter: new FileParameter(File.OpenRead("model.ifc"), "model.ifc"), where the second argument is the file name the server sees.

Many calls#

The SDK's default token provider hands out a token at most 25 times a second. A program that makes many calls registers a provider of its own, once, and sets the token after the login:

.NET#
using BIMworks.Sdk;

var services = new ServiceCollection();
services.AddApi(options =>
{
    options.UseProvider<Bearer, BearerToken>();
    options.AddApiHttpClients(http =>
    {
        http.BaseAddress = new Uri("https://bim.works" + "/openapi");
        http.Timeout = Timeout.InfiniteTimeSpan;
    });
});
var client = services.BuildServiceProvider();
var login = await client.GetRequiredService<IAuthApi>().LoginWithApiTokenAsync(new LoginWithApiTokenRequest("<your API token>"));
var auth = login.Ok()?.Auth ?? throw new HttpRequestException(login.RawContent, null, login.StatusCode);
client.GetRequiredService<Bearer>().Token = new BearerToken(auth.Base64);

/// <summary>Hands every call the bearer token of the login.</summary>
class Bearer : TokenProvider<BearerToken>
{
    public BearerToken Token { get; set; } = new("");

    protected override ValueTask<BearerToken> GetAsync(string header = "", CancellationToken cancellation = default) => new(Token);
}

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.