Reference·.NET SDK · BIMworks.Sdk.NET

WorkspacesApi

.NET SDK: the Workspaces operations, 5 methods, each with its parameters, result and a complete example.

.NET SDK · BIMworks.Sdk.Api · class · 5 methods

Curated views on a folder for visitors of the BIM.works web app, and their share links

Construct it with the client of the connect step: client.GetRequiredService<IWorkspacesApi>(). Each method is one operation of the API part, where it runs on its page.

MethodOperationDescription
CreateWorkspaceAsyncCreateWorkspaceCreate a workspace
DeleteWorkspaceAsyncDeleteWorkspaceDelete a workspace
ListWorkspacesAsyncListWorkspacesList the caller's workspaces
PublishWorkspaceAsyncPublishWorkspacePublish or unpublish a workspace
UpdateWorkspaceAsyncUpdateWorkspaceChange a workspace

CreateWorkspaceAsync#

.NET#
Task<ICreateWorkspaceApiResponse> CreateWorkspaceAsync(CreateWorkspaceRequest createWorkspaceRequest, CancellationToken cancellationToken = default)

Create a workspace. An account only. A sub-workspace inherits the root folder and the scopes of its parent and can only narrow them.

OperationCreateWorkspace · POST /openapi/workspaces/CreateWorkspace
Scopeworkspaces:write

Parameters#

NameTypeDescription
createWorkspaceRequestCreateWorkspaceRequestrequiredThe request: its properties are those of the model, its JSON that of CreateWorkspace's request body.

Returns#

CreateWorkspace200Response — The new workspace

Example#

.NET#
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
var request = JsonSerializer.Deserialize<CreateWorkspaceRequest>("""
    {
      "name": "",
      "parent_workspace_uuid": "00000000-0000-0000-0000-000000000000",
      "scopes": {},
      "filter": "",
      "load_all_models_initially": false,
      "current_space": {},
      "feature_visibility": {}
    }
    """, json);

// 3. The call
var response = await client.GetRequiredService<IWorkspacesApi>().CreateWorkspaceAsync(request);

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

DeleteWorkspaceAsync#

.NET#
Task<IDeleteWorkspaceApiResponse> DeleteWorkspaceAsync(DeleteWorkspaceRequest deleteWorkspaceRequest, CancellationToken cancellationToken = default)

Delete a workspace. Deletes the workspace and its sub-workspaces; their links stop working. The models and actions are kept. Its owner only.

OperationDeleteWorkspace · POST /openapi/workspaces/DeleteWorkspace
Scopeworkspaces:write

Parameters#

NameTypeDescription
deleteWorkspaceRequestDeleteWorkspaceRequestrequiredThe request: its properties are those of the model, its JSON that of DeleteWorkspace's request body.

Returns#

Nothing: the operation answers without a body (Deleted).

Example#

.NET#
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
var request = JsonSerializer.Deserialize<DeleteWorkspaceRequest>("""
    {
      "uuid": "<version uuid of the first demo model>"
    }
    """, json);

// 3. The call
var response = await client.GetRequiredService<IWorkspacesApi>().DeleteWorkspaceAsync(request);

// 4. The result
// (DeleteWorkspace answers no content: the call returns once it succeeded and throws an HttpRequestException otherwise)
if (!response.IsSuccessStatusCode) throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine("Done");

ListWorkspacesAsync#

.NET#
Task<IListWorkspacesApiResponse> ListWorkspacesAsync(CancellationToken cancellationToken = default)

List the caller's workspaces. The caller's workspaces with their sub-workspaces (children). A workspace is a curated view on a folder for visitors of the BIM.works web app: its scopes, object filter and visible features; PublishWorkspace makes it a share link.

OperationListWorkspaces · POST /openapi/workspaces/ListWorkspaces
Scopeworkspaces:read

Parameters#

None: the operation takes no request.

Returns#

List<Workspace> — The workspaces

Example#

.NET#
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
// (ListWorkspaces takes no request)

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

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

PublishWorkspaceAsync#

.NET#
Task<IPublishWorkspaceApiResponse> PublishWorkspaceAsync(PublishWorkspaceRequest publishWorkspaceRequest, CancellationToken cancellationToken = default)

Publish or unpublish a workspace. Publishing gives the workspace a new publish_uuid, the share link into the web app; publishing again replaces the link and ends the old one. publish: false unpublishes it and ends the visitors' sessions. Its owner only.

OperationPublishWorkspace · POST /openapi/workspaces/PublishWorkspace
Scopeworkspaces:write

Parameters#

NameTypeDescription
publishWorkspaceRequestPublishWorkspaceRequestrequiredThe request: its properties are those of the model, its JSON that of PublishWorkspace's request body.

Returns#

Workspace — The workspace with its publish_uuid

Example#

.NET#
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
var request = JsonSerializer.Deserialize<PublishWorkspaceRequest>("""
    {
      "uuid": "<version uuid of the first demo model>",
      "publish": true
    }
    """, json);

// 3. The call
var response = await client.GetRequiredService<IWorkspacesApi>().PublishWorkspaceAsync(request);

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

UpdateWorkspaceAsync#

.NET#
Task<IUpdateWorkspaceApiResponse> UpdateWorkspaceAsync(UpdateWorkspaceRequest updateWorkspaceRequest, CancellationToken cancellationToken = default)

Change a workspace. Changes the fields that are passed; the others stay as they are. A field named in clear is removed. Its owner only.

OperationUpdateWorkspace · POST /openapi/workspaces/UpdateWorkspace
Scopeworkspaces:write

Parameters#

NameTypeDescription
updateWorkspaceRequestUpdateWorkspaceRequestrequiredThe request: its properties are those of the model, its JSON that of UpdateWorkspace's request body.

Returns#

Nothing: the operation answers without a body (Changed).

Example#

.NET#
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
var request = JsonSerializer.Deserialize<UpdateWorkspaceRequest>("""
    {
      "uuid": "<version uuid of the first demo model>",
      "name": "",
      "scopes": {},
      "filter": "",
      "load_all_models_initially": false,
      "current_space": {},
      "feature_visibility": {},
      "sub_path": "",
      "clear": [
        "filter"
      ]
    }
    """, json);

// 3. The call
var response = await client.GetRequiredService<IWorkspacesApi>().UpdateWorkspaceAsync(request);

// 4. The result
// (UpdateWorkspace answers no content: the call returns once it succeeded and throws an HttpRequestException otherwise)
if (!response.IsSuccessStatusCode) throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine("Done");