ActionsApi
.NET SDK: the Actions operations, 6 methods, each with its parameters, result and a complete example.
.NET SDK · BIMworks.Sdk.Api · class · 6 methods
Stored queries, checks, visualizations and other actions, which Query and Check run by uuid
Construct it with the client of the connect step: client.GetRequiredService<IActionsApi>(). Each method is one operation of the API part, where it runs on its page.
| Method | Operation | Description |
|---|---|---|
AddActionAsync | AddAction | Store an action |
DeleteActionAsync | DeleteAction | Delete an action |
GetActionAsync | GetAction | Read an action |
ListActionsAsync | ListActions | List the actions in a folder |
UndeleteActionAsync | UndeleteAction | Bring back a deleted action |
UpdateActionAsync | UpdateAction | Change an action |
AddActionAsync#
Task<IAddActionApiResponse> AddActionAsync(AddActionRequest addActionRequest, CancellationToken cancellationToken = default)Store an action. Stores a query, check, visualization or other action in a folder, or a new folder (main_type: FOLDER). Needs write rights on the folder.
| Operation | AddAction · POST /openapi/actions/AddAction |
|---|---|
| Scope | actions:write |
Parameters#
| Name | Type | Description |
|---|---|---|
addActionRequest | AddActionRequestrequired | The request: its properties are those of the model, its JSON that of AddAction's request body. |
Returns#
BimAction — The stored action
Example#
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<AddActionRequest>("""
{
"parent_uuid": "5e4d3c2b-1a09-4f8e-9d7c-6b5a49382716",
"name": "External walls",
"main_type": "QUERY3",
"query": "GET attribute.Name WHERE type = IFCWALL AND property.Pset_WallCommon.IsExternal = true"
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IActionsApi>().AddActionAsync(request);
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result, json));DeleteActionAsync#
Task<IDeleteActionApiResponse> DeleteActionAsync(DeleteActionRequest deleteActionRequest, CancellationToken cancellationToken = default)Delete an action. Moves the action to the deleted ones (ListActions show_deleted); UndeleteAction brings it back.
| Operation | DeleteAction · POST /openapi/actions/DeleteAction |
|---|---|
| Scope | actions:write |
Parameters#
| Name | Type | Description |
|---|---|---|
deleteActionRequest | DeleteActionRequestrequired | The request: its properties are those of the model, its JSON that of DeleteAction's request body. |
Returns#
Nothing: the operation answers without a body (Deleted).
Example#
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<DeleteActionRequest>("""
{
"uuid": "<version uuid of the first demo model>"
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IActionsApi>().DeleteActionAsync(request);
// 4. The result
// (DeleteAction 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");GetActionAsync#
Task<IGetActionApiResponse> GetActionAsync(Option<GetActionRequest> getActionRequest = default, CancellationToken cancellationToken = default)Read an action. One action with its text, by uuid or by path (from the caller's own folder).
| Operation | GetAction · POST /openapi/actions/GetAction |
|---|---|
| Scope | actions:read |
Parameters#
| Name | Type | Description |
|---|---|---|
getActionRequest | GetActionRequestoptional | The request: its properties are those of the model, its JSON that of GetAction's request body. |
Returns#
BimAction — The action
Example#
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<GetActionRequest>("""
{
"uuid": "<version uuid of the first demo model>",
"path": ""
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IActionsApi>().GetActionAsync(request);
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result, json));ListActionsAsync#
Task<IListActionsApiResponse> ListActionsAsync(Option<ListActionsRequest> listActionsRequest = default, CancellationToken cancellationToken = default)List the actions in a folder. The stored actions (queries, checks, visualizations, ...) and folders in a folder, by name, and the folder's path. The folder by uuid or by path (from the caller's own folder); the caller's own folder when both are absent. Query and Check run a stored action by its uuid (action_uuid).
| Operation | ListActions · POST /openapi/actions/ListActions |
|---|---|
| Scope | actions:read |
Parameters#
| Name | Type | Description |
|---|---|---|
listActionsRequest | ListActionsRequestoptional | The request: its properties are those of the model, its JSON that of ListActions's request body. |
Returns#
ActionList — The folder's content
Example#
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<ListActionsRequest>("""
{
"uuid": "<version uuid of the first demo model>",
"path": "",
"show_deleted": false
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IActionsApi>().ListActionsAsync(request);
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result, json));UndeleteActionAsync#
Task<IUndeleteActionApiResponse> UndeleteActionAsync(UndeleteActionRequest undeleteActionRequest, CancellationToken cancellationToken = default)Bring back a deleted action. Undoes DeleteAction.
| Operation | UndeleteAction · POST /openapi/actions/UndeleteAction |
|---|---|
| Scope | actions:write |
Parameters#
| Name | Type | Description |
|---|---|---|
undeleteActionRequest | UndeleteActionRequestrequired | The request: its properties are those of the model, its JSON that of UndeleteAction's request body. |
Returns#
Nothing: the operation answers without a body (Restored).
Example#
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<UndeleteActionRequest>("""
{
"uuid": "<version uuid of the first demo model>"
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IActionsApi>().UndeleteActionAsync(request);
// 4. The result
// (UndeleteAction 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");UpdateActionAsync#
Task<IUpdateActionApiResponse> UpdateActionAsync(UpdateActionRequest updateActionRequest, CancellationToken cancellationToken = default)Change an action. Changes the fields that are passed; the others stay as they are. A change to an action (not a folder) is a new version unless save_mode is OVERWRITE. Pass base_version, the version you started from, to have a change by someone else in between refused with 409 instead of overwritten. A folder takes only a new name.
| Operation | UpdateAction · POST /openapi/actions/UpdateAction |
|---|---|
| Scope | actions:write |
Parameters#
| Name | Type | Description |
|---|---|---|
updateActionRequest | UpdateActionRequestrequired | The request: its properties are those of the model, its JSON that of UpdateAction's request body. |
Returns#
BimAction — The action as it is now
Example#
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<UpdateActionRequest>("""
{
"uuid": "<version uuid of the first demo model>",
"name": "",
"query": "",
"description": "",
"output_hint": "VIEWER_3D",
"favourite": false,
"save_mode": "NEW_VERSION",
"save_comment": "",
"base_version": 0
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IActionsApi>().UpdateActionAsync(request);
// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result, json));