Reference·.NET SDK · BIMworks.Sdk.NET

AccountApi

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

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

The signed-in account: registration, password, sessions and settings

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

MethodOperationDescription
ChangePasswordAsyncChangePasswordChange the password
GetSettingsAsyncGetSettingsRead the account settings
ListReferenceValuesAsyncListReferenceValuesThe values of the settings form
LogoutAsyncLogoutRecord a sign-out
RegisterAsyncRegisterRegister an account
RequestPasswordResetAsyncRequestPasswordResetSend a password reset e-mail
RequestValidationEmailAsyncRequestValidationEmailSend a new validation e-mail
SaveSettingsAsyncSaveSettingsChange the account settings
SignOutOtherSessionsAsyncSignOutOtherSessionsSign out every other session
ValidateEmailAddressAsyncValidateEmailAddressConfirm an e-mail address and set the password

ChangePasswordAsync#

.NET#
Task<IChangePasswordApiResponse> ChangePasswordAsync(ChangePasswordRequest changePasswordRequest, CancellationToken cancellationToken = default)

Change the password. Changes the password of the signed-in account and signs out every other session; this one continues on the session answered here. An account session only: an API token is refused. current_password is needed when the account has a password, code when it has two-factor authentication. An account without a password (one that signs in with e-mail codes) gets its first one, which needs a session signed in within the last 10 minutes.

OperationChangePassword · POST /openapi/account/ChangePassword
Scopeaccount:write

Parameters#

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

Returns#

AuthResult — The new session

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<ChangePasswordRequest>("""
    {
      "current_password": "",
      "password": "",
      "code": 0,
      "response_format": "auth"
    }
    """, json);

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

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

GetSettingsAsync#

.NET#
Task<IGetSettingsApiResponse> GetSettingsAsync(CancellationToken cancellationToken = default)

Read the account settings. The settings of the account behind the credential: name, country, language, time zone and the web app preferences. With an API token, those of the account that created it.

OperationGetSettings · POST /openapi/account/GetSettings
Scopeaccount:read

Parameters#

None: the operation takes no request.

Returns#

AccountSettings — The settings

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
// (GetSettings takes no request)

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

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

ListReferenceValuesAsync#

.NET#
Task<IListReferenceValuesApiResponse> ListReferenceValuesAsync(ListReferenceValuesRequest listReferenceValuesRequest, CancellationToken cancellationToken = default)

The values of the settings form. The countries (ISO 3166 codes), languages (ISO 639-1 codes) or time zones (tz identifiers) that the settings take, with a name to show. Names are in English.

OperationListReferenceValues · POST /openapi/account/ListReferenceValues
Scopeany login

Parameters#

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

Returns#

List<ReferenceValue> — The values

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<ListReferenceValuesRequest>("""
    {
      "kind": "countries"
    }
    """, json);

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

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

LogoutAsync#

.NET#
Task<ILogoutApiResponse> LogoutAsync(CancellationToken cancellationToken = default)

Record a sign-out. Records that the session signed out. It revokes nothing: the bearer token stays valid until it expires. To end sessions, use SignOutOtherSessions or ChangePassword.

OperationLogout · POST /openapi/account/Logout
Scopeany login

Parameters#

None: the operation takes no request.

Returns#

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

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
// (Logout takes no request)

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

// 4. The result
// (Logout 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");

RegisterAsync#

.NET#
Task<IRegisterApiResponse> RegisterAsync(RegisterRequest registerRequest, CancellationToken cancellationToken = default)

Register an account. Creates an account for an e-mail address and sends it the validation e-mail; the account is usable once the address is confirmed with ValidateEmailAddress. Refused (REGISTRATION_NOT_ALLOWED) when the instance does not allow self-registration (security.account_self_registration) or the address asked too often; an address that already has an account is refused with EMAIL_ADDRESS_ALREADY_REGISTERED.

OperationRegister · POST /openapi/account/Register
Scopenone: callable before logging in

Parameters#

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

Returns#

Nothing: the operation answers without a body (The validation e-mail is sent).

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 (Register needs no login)
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 client = Connect("");
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;

// 2. The request
var request = JsonSerializer.Deserialize<RegisterRequest>("""
    {
      "username": "",
      "preferred_language": ""
    }
    """, json);

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

// 4. The result
// (Register 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");

RequestPasswordResetAsync#

.NET#
Task<IRequestPasswordResetApiResponse> RequestPasswordResetAsync(RequestPasswordResetRequest requestPasswordResetRequest, CancellationToken cancellationToken = default)

Send a password reset e-mail. Sends a link to reset the password. The reset itself is completed in the BIM.works web app. It answers the same whether or not the account exists.

OperationRequestPasswordReset · POST /openapi/account/RequestPasswordReset
Scopenone: callable before logging in

Parameters#

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

Returns#

Nothing: the operation answers without a body (Done (whether or not an e-mail was sent)).

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 (RequestPasswordReset needs no login)
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 client = Connect("");
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;

// 2. The request
var request = JsonSerializer.Deserialize<RequestPasswordResetRequest>("""
    {
      "username": ""
    }
    """, json);

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

// 4. The result
// (RequestPasswordReset 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");

RequestValidationEmailAsync#

.NET#
Task<IRequestValidationEmailApiResponse> RequestValidationEmailAsync(RequestValidationEmailRequest requestValidationEmailRequest, CancellationToken cancellationToken = default)

Send a new validation e-mail. A new validation link for an address that registered but did not confirm yet. It answers the same whether or not such an account exists.

OperationRequestValidationEmail · POST /openapi/account/RequestValidationEmail
Scopenone: callable before logging in

Parameters#

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

Returns#

Nothing: the operation answers without a body (Done (whether or not an e-mail was sent)).

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 (RequestValidationEmail needs no login)
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 client = Connect("");
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;

// 2. The request
var request = JsonSerializer.Deserialize<RequestValidationEmailRequest>("""
    {
      "username": ""
    }
    """, json);

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

// 4. The result
// (RequestValidationEmail 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");

SaveSettingsAsync#

.NET#
Task<ISaveSettingsApiResponse> SaveSettingsAsync(AccountSettings accountSettings, CancellationToken cancellationToken = default)

Change the account settings. Changes the settings that are passed; the others stay as they are. With an API token, those of the account that created it.

OperationSaveSettings · POST /openapi/account/SaveSettings
Scopeaccount:write

Parameters#

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

Returns#

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

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<AccountSettings>("""
    {
      "full_name": "",
      "country_code": "",
      "preferred_language": "",
      "time_zone_id": "",
      "bim_context": "",
      "show_deleted_nodes": false,
      "email_about_vulnerabilities": false,
      "ui_mode": "END_USER"
    }
    """, json);

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

// 4. The result
// (SaveSettings 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");

SignOutOtherSessionsAsync#

.NET#
Task<ISignOutOtherSessionsApiResponse> SignOutOtherSessionsAsync(Option<SignOutOtherSessionsRequest> signOutOtherSessionsRequest = default, CancellationToken cancellationToken = default)

Sign out every other session. Ends every session of the signed-in account except this one, which continues on the session answered here: for a lost or shared device. An account session only. API tokens are separate credentials and keep working; revoke them with DeleteApiToken.

OperationSignOutOtherSessions · POST /openapi/account/SignOutOtherSessions
Scopeaccount:write

Parameters#

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

Returns#

AuthResult — The new session

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<SignOutOtherSessionsRequest>("""
    {
      "response_format": "auth"
    }
    """, json);

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

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

ValidateEmailAddressAsync#

.NET#
Task<IValidateEmailAddressApiResponse> ValidateEmailAddressAsync(ValidateEmailAddressRequest validateEmailAddressRequest, CancellationToken cancellationToken = default)

Confirm an e-mail address and set the password. Confirms the address with the token from the validation e-mail and sets the account's password (8 to 128 characters, not a common one, not the address). It does not sign in: use LoginWithUsernamePassword after. The link is valid for a day.

OperationValidateEmailAddress · POST /openapi/account/ValidateEmailAddress
Scopenone: callable before logging in

Parameters#

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

Returns#

Nothing: the operation answers without a body (The address is confirmed).

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 (ValidateEmailAddress needs no login)
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 client = Connect("");
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;

// 2. The request
var request = JsonSerializer.Deserialize<ValidateEmailAddressRequest>("""
    {
      "username": "",
      "token": "",
      "password": ""
    }
    """, json);

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

// 4. The result
// (ValidateEmailAddress 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");