Delete and restore a node
Soft-delete a node so it disappears from listings, and restore it later; what cannot be deleted and when a restore fails.
For clean-up in an integration. Deleting a node is a soft delete: the node and everything below it vanish from listings, queries and viewers, but nothing is removed from storage, and UndeleteNode brings the node back with all its versions.
Before you start#
- A login with the
fs:writescope and write rights on the node (Log in with an API token). - The node's UUID (List the tree).
1. Delete#
await client.fs.deleteNode(nodeUuid);client.fs.deleteNode(nodeUuid);client.Fs.DeleteNode(nodeUuid);import nl.bimbase.bimworks.sdk.api.AuthApi;
import nl.bimbase.bimworks.sdk.api.FsApi;
import nl.bimbase.bimworks.sdk.client.ApiClient;
import nl.bimbase.bimworks.sdk.model.Auth;
import nl.bimbase.bimworks.sdk.model.DeleteNodeRequest;
import nl.bimbase.bimworks.sdk.model.LoginWithApiTokenRequest;
public class Example {
public static void main(String[] args) throws Exception {
// 1. Connect to BIM.works and log in with your API token
ApiClient client = new ApiClient();
client.updateBaseUri("https://bim.works/openapi");
Auth auth = new AuthApi(client)
.loginWithApiToken(new LoginWithApiTokenRequest().token("<your API token>"))
.getAuth();
client.setRequestInterceptor(builder -> builder.setHeader("Authorization", "Bearer " + auth.getBase64()));
// 2. The request
DeleteNodeRequest request = client.getObjectMapper().readValue("""
{
"uuid": "<node uuid>"
}
""", DeleteNodeRequest.class);
// 3. The call
new FsApi(client).deleteNode(request);
// 4. The result
// (DeleteNode answers no content: the call returns once it succeeded and throws an ApiException otherwise)
System.out.println("Done");
}
}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<DeleteNodeRequest>("""
{
"uuid": "<node uuid>"
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IFsApi>().DeleteNodeAsync(request);
// 4. The result
// (DeleteNode 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");import { AuthApi, Configuration, DeleteNodeRequestFromJSON, FsApi } from "@bimworks/sdk";
// 1. Connect to BIM.works and log in with your API token
const basePath = "https://bim.works/openapi";
const auth = await new AuthApi(new Configuration({ basePath }))
.loginWithApiToken({ loginWithApiTokenRequest: { token: "<your API token>" } });
const client = new Configuration({ basePath, accessToken: typeof auth === "string" ? auth : auth.base64 });
// 2. The request
const request = DeleteNodeRequestFromJSON({
"uuid": "<node uuid>"
});
// 3. The call
await new FsApi(client).deleteNode({ deleteNodeRequest: request });
// 4. The result
// (DeleteNode answers no content: the call returns once it succeeded and throws a ResponseError otherwise)
console.log("Done");<?php
require __DIR__ . '/vendor/autoload.php';
use BIMworks\Api\AuthApi;
use BIMworks\Api\FsApi;
use BIMworks\Configuration;
use BIMworks\Model\DeleteNodeRequest;
use BIMworks\Model\LoginWithApiTokenRequest;
use BIMworks\ObjectSerializer;
// 1. Connect to BIM.works and log in with your API token
$client = (new Configuration())->setHost('https://bim.works/openapi');
$auth = (new AuthApi(config: $client))->loginWithApiToken(new LoginWithApiTokenRequest(['token' => "<your API token>"]));
$client->setAccessToken($auth->getBase64());
// 2. The request
$request = ObjectSerializer::deserialize(<<<'JSON'
{
"uuid": "<node uuid>"
}
JSON, DeleteNodeRequest::class);
// 3. The call
(new FsApi(config: $client))->deleteNode($request);
// 4. The result
// (DeleteNode answers no content: the call returns once it succeeded and throws an ApiException otherwise)
echo 'Done', PHP_EOL;import bimworks
# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64
# 2. The request
request = bimworks.DeleteNodeRequest.from_json(r"""
{
"uuid": "<node uuid>"
}
""")
# 3. The call
bimworks.FsApi(client).delete_node(request)
# 4. The result
# (DeleteNode answers no content: the call returns once it succeeded and throws a bimworks.ApiException otherwise)
print("Done")deleteNode is on Fs and FileSystemApi, DeleteNode on Fs, FsApi::deleteNode in PHP SDK; over HTTP DeleteNode:
Bearer <auth token>application/jsonAuthorization: Bearer <auth token>
Content-Type: application/json
Accept: application/jsoncurl -X POST "$BIMWORKS_URL/openapi/fs/DeleteNode" \
-H "Authorization: Bearer $BIMWORKS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"uuid": "<node uuid>"
}'Two nodes refuse: the root node of an account (CANNOT_DELETE_USER_FOLDER) and the root node of an API token (CANNOT_DELETE_API_TOKEN_FOLDER). Deleting a folder deletes its subtree with it. The Java and .NET SDKs also offer deleteNodeIfExists(path), which does nothing for a path that does not exist, handy in test set-ups.
2. Restore#
await client.fs.undeleteNode(nodeUuid);client.fs.undeleteNode(nodeUuid);client.Fs.UndeleteNode(nodeUuid);import nl.bimbase.bimworks.sdk.api.AuthApi;
import nl.bimbase.bimworks.sdk.api.FsApi;
import nl.bimbase.bimworks.sdk.client.ApiClient;
import nl.bimbase.bimworks.sdk.model.Auth;
import nl.bimbase.bimworks.sdk.model.LoginWithApiTokenRequest;
import nl.bimbase.bimworks.sdk.model.UndeleteNodeRequest;
public class Example {
public static void main(String[] args) throws Exception {
// 1. Connect to BIM.works and log in with your API token
ApiClient client = new ApiClient();
client.updateBaseUri("https://bim.works/openapi");
Auth auth = new AuthApi(client)
.loginWithApiToken(new LoginWithApiTokenRequest().token("<your API token>"))
.getAuth();
client.setRequestInterceptor(builder -> builder.setHeader("Authorization", "Bearer " + auth.getBase64()));
// 2. The request
UndeleteNodeRequest request = client.getObjectMapper().readValue("""
{
"uuid": "<node uuid>"
}
""", UndeleteNodeRequest.class);
// 3. The call
new FsApi(client).undeleteNode(request);
// 4. The result
// (UndeleteNode answers no content: the call returns once it succeeded and throws an ApiException otherwise)
System.out.println("Done");
}
}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<UndeleteNodeRequest>("""
{
"uuid": "<node uuid>"
}
""", json);
// 3. The call
var response = await client.GetRequiredService<IFsApi>().UndeleteNodeAsync(request);
// 4. The result
// (UndeleteNode 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");import { AuthApi, Configuration, FsApi, UndeleteNodeRequestFromJSON } from "@bimworks/sdk";
// 1. Connect to BIM.works and log in with your API token
const basePath = "https://bim.works/openapi";
const auth = await new AuthApi(new Configuration({ basePath }))
.loginWithApiToken({ loginWithApiTokenRequest: { token: "<your API token>" } });
const client = new Configuration({ basePath, accessToken: typeof auth === "string" ? auth : auth.base64 });
// 2. The request
const request = UndeleteNodeRequestFromJSON({
"uuid": "<node uuid>"
});
// 3. The call
await new FsApi(client).undeleteNode({ undeleteNodeRequest: request });
// 4. The result
// (UndeleteNode answers no content: the call returns once it succeeded and throws a ResponseError otherwise)
console.log("Done");<?php
require __DIR__ . '/vendor/autoload.php';
use BIMworks\Api\AuthApi;
use BIMworks\Api\FsApi;
use BIMworks\Configuration;
use BIMworks\Model\LoginWithApiTokenRequest;
use BIMworks\Model\UndeleteNodeRequest;
use BIMworks\ObjectSerializer;
// 1. Connect to BIM.works and log in with your API token
$client = (new Configuration())->setHost('https://bim.works/openapi');
$auth = (new AuthApi(config: $client))->loginWithApiToken(new LoginWithApiTokenRequest(['token' => "<your API token>"]));
$client->setAccessToken($auth->getBase64());
// 2. The request
$request = ObjectSerializer::deserialize(<<<'JSON'
{
"uuid": "<node uuid>"
}
JSON, UndeleteNodeRequest::class);
// 3. The call
(new FsApi(config: $client))->undeleteNode($request);
// 4. The result
// (UndeleteNode answers no content: the call returns once it succeeded and throws an ApiException otherwise)
echo 'Done', PHP_EOL;import bimworks
# 1. Connect to BIM.works and log in with your API token
client = bimworks.ApiClient(bimworks.Configuration(host="https://bim.works/openapi"))
auth = bimworks.AuthApi(client).login_with_api_token(
bimworks.LoginWithApiTokenRequest(token="<your API token>"))
client.configuration.access_token = auth.actual_instance.var_base64
# 2. The request
request = bimworks.UndeleteNodeRequest.from_json(r"""
{
"uuid": "<node uuid>"
}
""")
# 3. The call
bimworks.FsApi(client).undelete_node(request)
# 4. The result
# (UndeleteNode answers no content: the call returns once it succeeded and throws a bimworks.ApiException otherwise)
print("Done")undeleteNode is on Fs and FileSystemApi, UndeleteNode on Fs, FsApi::undeleteNode in PHP SDK; over HTTP UndeleteNode with the same uuid body. A restore fails with CANNOT_UNDELETE_NAME_CONFLICT when the parent meanwhile got another node with the same name; rename or delete that one first.
3. Know what stays#
- A deleted node is invisible to API tokens and delegated tokens; an account with the super-admin role can list deleted nodes with
show_deleted_nodeson ListNodes, which is how you find a UUID you did not keep. - Versions are not deleted by deleting the node; they come back with it. To drop a single version, use DeleteVersion (
deleteNodeVersionin the SDKs): only the last version of a node can be deleted (CAN_ONLY_DELETE_LAST_VERSION). - Delegated tokens that name the node keep naming it; they simply cannot read it while it is deleted (
AuthorizationError.NO_READ_RIGHTS).
Check#
After the delete, listNodes of the parent no longer shows the node and getNodeByUuid fails with AuthorizationError.NO_READ_RIGHTS; after the restore, both work again and the node's versions are unchanged (List the tree).