---
title: .NET SDK
summary: 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.
order: 20
languages: [csharp]
terms: [sdk, openapi, api-token, auth-token, scope]
see-also: [reference/sdk, how-to/install/dotnet, api, reference/dotnet]
---

# .NET SDK

The .NET [[term:sdk|SDK]] is generated from the [[term:openapi|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 [[page:reference/dotnet|classic .NET SDK]] (`BIM.works_SDK`) is a different, hand-written client; the two can be used side by side.

## Package {#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 {#csproj}
<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 {#connect}

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, [[openapi:LoginWithApiToken]] with your [[term:api-token|API token]], and once with the [[term:auth-token|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.

```sdk-example {#quick-start}
operation: GetRootNodeUuid
languages: csharp
```

## Every example in four steps {#example-shape}

Every example on these pages and on the operation pages of the [[page:api|API part]] is a complete program in the same four steps ([[page: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, [[openapi: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 {#classes}

<table class="dense">
<thead><tr><th>Class</th><th>Group</th><th>Methods</th></tr></thead>
<tbody>
<tr><td>[[page:reference/sdk/dotnet/actionsapi|ActionsApi]]</td><td>Actions</td><td>[[page:reference/sdk/dotnet/actionsapi#addaction|AddActionAsync]], [[page:reference/sdk/dotnet/actionsapi#deleteaction|DeleteActionAsync]], [[page:reference/sdk/dotnet/actionsapi#getaction|GetActionAsync]], [[page:reference/sdk/dotnet/actionsapi#listactions|ListActionsAsync]], [[page:reference/sdk/dotnet/actionsapi#undeleteaction|UndeleteActionAsync]], [[page:reference/sdk/dotnet/actionsapi#updateaction|UpdateActionAsync]]</td></tr>
<tr><td>[[page:reference/sdk/dotnet/linkeddataapi|LinkedDataApi]]</td><td>Linked data</td><td>[[page:reference/sdk/dotnet/linkeddataapi#addlinktargets|AddLinkTargetsAsync]], [[page:reference/sdk/dotnet/linkeddataapi#confirmlinkmatch|ConfirmLinkMatchAsync]], [[page:reference/sdk/dotnet/linkeddataapi#deletelinkeddata|DeleteLinkedDataAsync]], [[page:reference/sdk/dotnet/linkeddataapi#downloadlinkeddata|DownloadLinkedDataAsync]], [[page:reference/sdk/dotnet/linkeddataapi#endlink|EndLinkAsync]], [[page:reference/sdk/dotnet/linkeddataapi#getlinkeddata|GetLinkedDataAsync]], [[page:reference/sdk/dotnet/linkeddataapi#getlinkeddatacounts|GetLinkedDataCountsAsync]], [[page:reference/sdk/dotnet/linkeddataapi#getlinkeddatapolicy|GetLinkedDataPolicyAsync]], [[page:reference/sdk/dotnet/linkeddataapi#linkdata|LinkDataAsync]], [[page:reference/sdk/dotnet/linkeddataapi#listlinkeddata|ListLinkedDataAsync]], [[page:reference/sdk/dotnet/linkeddataapi#reattachlink|ReattachLinkAsync]], [[page:reference/sdk/dotnet/linkeddataapi#replacelinkeddata|ReplaceLinkedDataAsync]], [[page:reference/sdk/dotnet/linkeddataapi#restorelinkeddata|RestoreLinkedDataAsync]], [[page:reference/sdk/dotnet/linkeddataapi#unlinkdata|UnlinkDataAsync]], [[page:reference/sdk/dotnet/linkeddataapi#updatelinkeddata|UpdateLinkedDataAsync]]</td></tr>
<tr><td>[[page:reference/sdk/dotnet/modelapi|ModelApi]]</td><td>Model</td><td>[[page:reference/sdk/dotnet/modelapi#addmodelwithurl|AddModelWithUrlAsync]], [[page:reference/sdk/dotnet/modelapi#augmentbcf|AugmentBcfAsync]], [[page:reference/sdk/dotnet/modelapi#download|DownloadAsync]], [[page:reference/sdk/dotnet/modelapi#downloadifcxml|DownloadIfcXmlAsync]], [[page:reference/sdk/dotnet/modelapi#exportgeometry|ExportGeometryAsync]], [[page:reference/sdk/dotnet/modelapi#exportvectorsvg|ExportVectorSvgAsync]], [[page:reference/sdk/dotnet/modelapi#getcheckin|GetCheckinAsync]], [[page:reference/sdk/dotnet/modelapi#getvalidationreport|GetValidationReportAsync]], [[page:reference/sdk/dotnet/modelapi#lookupmodelhashes|LookupModelHashesAsync]], [[page:reference/sdk/dotnet/modelapi#render|RenderAsync]], [[page:reference/sdk/dotnet/modelapi#schemaconversionreport|SchemaConversionReportAsync]], [[page:reference/sdk/dotnet/modelapi#uploadmodel|UploadModelAsync]]</td></tr>
<tr><td>[[page:reference/sdk/dotnet/accountapi|AccountApi]]</td><td>Account</td><td>[[page:reference/sdk/dotnet/accountapi#changepassword|ChangePasswordAsync]], [[page:reference/sdk/dotnet/accountapi#getsettings|GetSettingsAsync]], [[page:reference/sdk/dotnet/accountapi#listreferencevalues|ListReferenceValuesAsync]], [[page:reference/sdk/dotnet/accountapi#logout|LogoutAsync]], [[page:reference/sdk/dotnet/accountapi#register|RegisterAsync]], [[page:reference/sdk/dotnet/accountapi#requestpasswordreset|RequestPasswordResetAsync]], [[page:reference/sdk/dotnet/accountapi#requestvalidationemail|RequestValidationEmailAsync]], [[page:reference/sdk/dotnet/accountapi#savesettings|SaveSettingsAsync]], [[page:reference/sdk/dotnet/accountapi#signoutothersessions|SignOutOtherSessionsAsync]], [[page:reference/sdk/dotnet/accountapi#validateemailaddress|ValidateEmailAddressAsync]]</td></tr>
<tr><td>[[page:reference/sdk/dotnet/ifcapi|IFCApi]]</td><td>IFC - Industry Foundation Classes</td><td>[[page:reference/sdk/dotnet/ifcapi#check|CheckAsync]], [[page:reference/sdk/dotnet/ifcapi#committransaction|CommitTransactionAsync]], [[page:reference/sdk/dotnet/ifcapi#comparemodels|CompareModelsAsync]], [[page:reference/sdk/dotnet/ifcapi#compareobjects|CompareObjectsAsync]], [[page:reference/sdk/dotnet/ifcapi#deletecomparepairoverride|DeleteComparePairOverrideAsync]], [[page:reference/sdk/dotnet/ifcapi#exportcompareresult|ExportCompareResultAsync]], [[page:reference/sdk/dotnet/ifcapi#getcomparebul|GetCompareBulAsync]], [[page:reference/sdk/dotnet/ifcapi#getcompareresult|GetCompareResultAsync]], [[page:reference/sdk/dotnet/ifcapi#getmatchcandidates|GetMatchCandidatesAsync]], [[page:reference/sdk/dotnet/ifcapi#getobjecthistory|GetObjectHistoryAsync]], [[page:reference/sdk/dotnet/ifcapi#getversionchanges|GetVersionChangesAsync]], [[page:reference/sdk/dotnet/ifcapi#listbuildingstoreys|ListBuildingStoreysAsync]], [[page:reference/sdk/dotnet/ifcapi#listcomparepairoverrides|ListComparePairOverridesAsync]], [[page:reference/sdk/dotnet/ifcapi#mapqids|MapQidsAsync]], [[page:reference/sdk/dotnet/ifcapi#parsequery|ParseQueryAsync]], [[page:reference/sdk/dotnet/ifcapi#query|QueryAsync]], [[page:reference/sdk/dotnet/ifcapi#recorduploadastransaction|RecordUploadAsTransactionAsync]], [[page:reference/sdk/dotnet/ifcapi#resolvebvl|ResolveBvlAsync]], [[page:reference/sdk/dotnet/ifcapi#setcomparepairoverride|SetComparePairOverrideAsync]], [[page:reference/sdk/dotnet/ifcapi#textsearch|TextSearchAsync]], [[page:reference/sdk/dotnet/ifcapi#upgradesyntax|UpgradeSyntaxAsync]]</td></tr>
<tr><td>[[page:reference/sdk/dotnet/gisapi|GISApi]]</td><td>GIS - Geographic Information Systems</td><td>[[page:reference/sdk/dotnet/gisapi#copygeoreference|CopyGeoReferenceAsync]], [[page:reference/sdk/dotnet/gisapi#exportcitygml3|ExportCityGML3Async]], [[page:reference/sdk/dotnet/gisapi#extractgeoreference|ExtractGeoReferenceAsync]], [[page:reference/sdk/dotnet/gisapi#generate3dtilesurl|Generate3DTilesUrlAsync]], [[page:reference/sdk/dotnet/gisapi#getgeoreference|GetGeoReferenceAsync]], [[page:reference/sdk/dotnet/gisapi#setgeoreference|SetGeoReferenceAsync]]</td></tr>
<tr><td>[[page:reference/sdk/dotnet/authapi|AuthApi]]</td><td>Auth - Authentication</td><td>[[page:reference/sdk/dotnet/authapi#createanonymoustoken|CreateAnonymousTokenAsync]], [[page:reference/sdk/dotnet/authapi#createapitoken|CreateApiTokenAsync]], [[page:reference/sdk/dotnet/authapi#createnodestoken|CreateNodesTokenAsync]], [[page:reference/sdk/dotnet/authapi#createrecursivenodetoken|CreateRecursiveNodeTokenAsync]], [[page:reference/sdk/dotnet/authapi#createversionstoken|CreateVersionsTokenAsync]], [[page:reference/sdk/dotnet/authapi#deleteapitoken|DeleteApiTokenAsync]], [[page:reference/sdk/dotnet/authapi#getsession|GetSessionAsync]], [[page:reference/sdk/dotnet/authapi#listapitokens|ListApiTokensAsync]], [[page:reference/sdk/dotnet/authapi#loginanonymous|LoginAnonymousAsync]], [[page:reference/sdk/dotnet/authapi#loginwithanonymoustoken|LoginWithAnonymousTokenAsync]], [[page:reference/sdk/dotnet/authapi#loginwithapitoken|LoginWithApiTokenAsync]], [[page:reference/sdk/dotnet/authapi#loginwithusernamepassword|LoginWithUsernamePasswordAsync]], [[page:reference/sdk/dotnet/authapi#updateapitoken|UpdateApiTokenAsync]]</td></tr>
<tr><td>[[page:reference/sdk/dotnet/fsapi|FsApi]]</td><td>Fs - FileSystem</td><td>[[page:reference/sdk/dotnet/fsapi#createnode|CreateNodeAsync]], [[page:reference/sdk/dotnet/fsapi#deletenode|DeleteNodeAsync]], [[page:reference/sdk/dotnet/fsapi#deletenodeerror|DeleteNodeErrorAsync]], [[page:reference/sdk/dotnet/fsapi#deleteversion|DeleteVersionAsync]], [[page:reference/sdk/dotnet/fsapi#downloadaszip|DownloadAsZipAsync]], [[page:reference/sdk/dotnet/fsapi#getnode|GetNodeAsync]], [[page:reference/sdk/dotnet/fsapi#getrootnodeuuid|GetRootNodeUuidAsync]], [[page:reference/sdk/dotnet/fsapi#getversion|GetVersionAsync]], [[page:reference/sdk/dotnet/fsapi#listnodeerrors|ListNodeErrorsAsync]], [[page:reference/sdk/dotnet/fsapi#listnodes|ListNodesAsync]], [[page:reference/sdk/dotnet/fsapi#listnodesrecursive|ListNodesRecursiveAsync]], [[page:reference/sdk/dotnet/fsapi#listversions|ListVersionsAsync]], [[page:reference/sdk/dotnet/fsapi#movenode|MoveNodeAsync]], [[page:reference/sdk/dotnet/fsapi#undeletenode|UndeleteNodeAsync]], [[page:reference/sdk/dotnet/fsapi#updatenode|UpdateNodeAsync]], [[page:reference/sdk/dotnet/fsapi#updateversion|UpdateVersionAsync]]</td></tr>
<tr><td>[[page:reference/sdk/dotnet/workspacesapi|WorkspacesApi]]</td><td>Workspaces</td><td>[[page:reference/sdk/dotnet/workspacesapi#createworkspace|CreateWorkspaceAsync]], [[page:reference/sdk/dotnet/workspacesapi#deleteworkspace|DeleteWorkspaceAsync]], [[page:reference/sdk/dotnet/workspacesapi#listworkspaces|ListWorkspacesAsync]], [[page:reference/sdk/dotnet/workspacesapi#publishworkspace|PublishWorkspaceAsync]], [[page:reference/sdk/dotnet/workspacesapi#updateworkspace|UpdateWorkspaceAsync]]</td></tr>
<tr><td>[[page:reference/sdk/dotnet/infoapi|InfoApi]]</td><td>Info</td><td>[[page:reference/sdk/dotnet/infoapi#getapplicationversion|GetApplicationVersionAsync]]</td></tr>
<tr><td>[[page:reference/sdk/dotnet/viewerapi|ViewerApi]]</td><td>Viewer</td><td>[[page:reference/sdk/dotnet/viewerapi#getgeometrymetadata|GetGeometryMetaDataAsync]]</td></tr>
<tr><td>[[page:reference/sdk/dotnet/adminapi|AdminApi]]</td><td>Admin</td><td>[[page:reference/sdk/dotnet/adminapi#listaccountuserfeatures|ListAccountUserFeaturesAsync]], [[page:reference/sdk/dotnet/adminapi#listaccounts|ListAccountsAsync]], [[page:reference/sdk/dotnet/adminapi#listorganizations|ListOrganizationsAsync]]</td></tr>
<tr><td>[[page:reference/sdk/dotnet/aiapi|AIApi]]</td><td>AI - Artificial Intelligence</td><td>[[page:reference/sdk/dotnet/aiapi#texttoaction|TextToActionAsync]]</td></tr>
<tr><td>[[page:reference/sdk/dotnet/versionsapi|VersionsApi]]</td><td>Versions</td><td>[[page:reference/sdk/dotnet/versionsapi#version|VersionAsync]]</td></tr>
<tr><td>[[page:reference/sdk/dotnet/models|Models]]</td><td>Requests and responses</td><td>289 model classes</td></tr>
</tbody>
</table>

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 [[page:reference/sdk/dotnet/models|models page]]. The schema `Action` is the class `BimAction`, which does not collide with `System.Action`.

## Responses and errors {#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, [[page:api/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:

```csharp {#error-example}
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`. [[openapi:UploadModel]] and [[openapi:AddModelWithUrl]] with `wait_ms`, [[openapi:CompareModels]] and [[openapi:GetCompareResult]] can answer `202`: `IsAccepted` and `Accepted()` give that answer.

## Files {#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 {#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:

```csharp {#provider}
using BIMworks.Sdk;

var services = new ServiceCollection();
services.AddApi(options =>
{
    options.UseProvider<Bearer, BearerToken>();
    options.AddApiHttpClients(http =>
    {
        http.BaseAddress = new Uri("BIM_WORKS_ADDRESS" + "/openapi");
        http.Timeout = Timeout.InfiniteTimeSpan;
    });
});
var client = services.BuildServiceProvider();
var login = await client.GetRequiredService<IAuthApi>().LoginWithApiTokenAsync(new LoginWithApiTokenRequest("BIM_WORKS_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);
}
```
