How-to guide·ModelsJavaScript · Java · .NET · PHP

Create a folder

Create a folder node under a parent, or get the existing one, in every SDK and over HTTP.

For an integration that organises its uploads: one folder per project, per user or per import run. A folder is a node like any other; the API tokens and delegated tokens you create later are rooted at folders, so the folder layout is also your permission layout.

Before you start#

1. Create the folder#

Classic SDK
const folderUuid = await client.fs.createNode(parentUuid, "Project A", true);
UUID folderUuid = client.fs.createNode(parentUuid, "Project A", true);
Guid folderUuid = client.Fs.CreateNode(parentUuid, "Project A", true, InputFileType.FOLDER);
OpenAPI SDK
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.CreateNodeRequest;
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
        CreateNodeRequest request = client.getObjectMapper().readValue("""
                {
                  "name": "Project A",
                  "folder": true,
                  "parent_node_uuid": "<parent uuid>"
                }
                """, CreateNodeRequest.class);

        // 3. The call
        var result = new FsApi(client).createNode(request);

        // 4. The result
        System.out.println(client.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(result));
    }
}
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<CreateNodeRequest>("""
    {
      "name": "Project A",
      "folder": true,
      "parent_node_uuid": "<parent uuid>"
    }
    """, json);

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

// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result, json));
import { AuthApi, Configuration, CreateNodeRequestFromJSON, FsApi, NodeToJSON } 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 = CreateNodeRequestFromJSON({
  "name": "Project A",
  "folder": true,
  "parent_node_uuid": "<parent uuid>"
});

// 3. The call
const result = await new FsApi(client).createNode({ createNodeRequest: request });

// 4. The result
console.log(JSON.stringify(NodeToJSON(result), null, 2));
<?php
require __DIR__ . '/vendor/autoload.php';

use BIMworks\Api\AuthApi;
use BIMworks\Api\FsApi;
use BIMworks\Configuration;
use BIMworks\Model\CreateNodeRequest;
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'
{
  "name": "Project A",
  "folder": true,
  "parent_node_uuid": "<parent uuid>"
}
JSON, CreateNodeRequest::class);

// 3. The call
$result = (new FsApi(config: $client))->createNode($request);

// 4. The result
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;
import json

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.CreateNodeRequest.from_json(r"""
{
  "name": "Project A",
  "folder": true,
  "parent_node_uuid": "<parent uuid>"
}
""")

# 3. The call
result = bimworks.FsApi(client).create_node(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

The SDK methods return the new node's UUID: createNode on Fs and FileSystemApi, CreateNode on Fs; the PHP FsApi::createNode (PHP SDK) and the HTTP operation CreateNode return the whole node:

POST/openapi/fs/CreateNodeCreateNode reference
Authorization
Bearer <auth token>
Content-Type
application/json
Body
1 2 3 4 5
Authorization: Bearer <auth token>
Content-Type: application/json
Accept: application/json
curl -X POST "$BIMWORKS_URL/openapi/fs/CreateNode" \
  -H "Authorization: Bearer $BIMWORKS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Project A",
  "folder": true,
  "parent_node_uuid": "<parent uuid>"
}'
Send to see the response

Without parent_node_uuid the folder is created in the root node of the credential. A name that already exists in the parent fails with NODE_ALREADY_EXISTS; a name that is not a valid path segment with INVALID_PATH.

2. Or create it only when it is missing#

Import runs that create the same folders every time use the idempotent variant: it returns the UUID of the existing node when the name is taken.

Classic SDK
const folderUuid = await client.fs.createNodeIfNotExists(parentUuid, "Project A", true);
UUID folderUuid = client.fs.createNodeIfNotExists(parentUuid, "Project A", true, null);
Guid folderUuid = client.Fs.CreateNodeIfNotExists(parentUuid, "Project A", true, InputFileType.FOLDER);
OpenAPI SDK
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.CreateNodeRequest;
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
        CreateNodeRequest request = client.getObjectMapper().readValue("""
                {
                  "name": "Project A",
                  "folder": true,
                  "parent_node_uuid": "<parent folder uuid>",
                  "allow_existing": true
                }
                """, CreateNodeRequest.class);

        // 3. The call
        var result = new FsApi(client).createNode(request);

        // 4. The result
        System.out.println(client.getObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(result));
    }
}
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<CreateNodeRequest>("""
    {
      "name": "Project A",
      "folder": true,
      "parent_node_uuid": "<parent folder uuid>",
      "allow_existing": true
    }
    """, json);

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

// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result, json));
import { AuthApi, Configuration, CreateNodeRequestFromJSON, FsApi, NodeToJSON } 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 = CreateNodeRequestFromJSON({
  "name": "Project A",
  "folder": true,
  "parent_node_uuid": "<parent folder uuid>",
  "allow_existing": true
});

// 3. The call
const result = await new FsApi(client).createNode({ createNodeRequest: request });

// 4. The result
console.log(JSON.stringify(NodeToJSON(result), null, 2));
<?php
require __DIR__ . '/vendor/autoload.php';

use BIMworks\Api\AuthApi;
use BIMworks\Api\FsApi;
use BIMworks\Configuration;
use BIMworks\Model\CreateNodeRequest;
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'
{
  "name": "Project A",
  "folder": true,
  "parent_node_uuid": "<parent folder uuid>",
  "allow_existing": true
}
JSON, CreateNodeRequest::class);

// 3. The call
$result = (new FsApi(config: $client))->createNode($request);

// 4. The result
echo json_encode($result, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), PHP_EOL;
import json

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.CreateNodeRequest.from_json(r"""
{
  "name": "Project A",
  "folder": true,
  "parent_node_uuid": "<parent folder uuid>",
  "allow_existing": true
}
""")

# 3. The call
result = bimworks.FsApi(client).create_node(request)

# 4. The result
print(json.dumps(client.sanitize_for_serialization(result), indent=2))

Over HTTP, allow_existing: true on CreateNode does the same.

Check#

getNodeByPath on the parent's path plus the new name returns a node whose folder is true and whose uuid is the one you got back (List the tree). Creating the same name again fails with NODE_ALREADY_EXISTS, unless you used the if-missing variant, which returns the same UUID.