Provision a linked workspace from a process
Document information
- Canonical URL:
/docs/05_apps-webhooks-and-surfaces/44_provision-a-linked-workspace - Version:
2026-11-26 - Tags:
workspaces,webapps,processflow,datapool
A process in the owner workspace can create a linked workspace and set that workspace up. It can add and publish WebApps, choose a public address, create a WebApp service account, add processes, create DataPool schemas and rows, and write text or binary files into that workspace's CDN folder. Organizations use the same calls for different jobs. One example, later on this page, publishes a recruiting application into a new workspace for each organization that signs up.
The process can be started from a published WebApp or on a schedule. The step needs the api capability. Call the API with tf.api.get, tf.api.post, and tf.api.put. See Process sandbox tf API.
A person signed in to the console still has to be an administrator of the owner workspace to create a linked workspace or to publish WebApps themselves. A process that runs inside a linked workspace cannot change the owner workspace.
What you prepare once
Keep the material the process copies — WebApp HTML, step source, and DataPool schema definitions — on the owner workspace, in DataPool rows or in documents. Editing those records changes what the next linked workspace receives. The example later stores one bookkeeping row per workspace in a schema named app_customers, with organization_name, admin_email, sibling_tenant_id, and public_url. Use whatever fields your own case needs.
The owner workspace must be on Basic, Premium, or Enterprise. Free and Starter cannot create linked workspaces. max_linked_workspaces on the owner subscription is how many linked workspaces you can create. Each plan can set its own number, and one workspace can be given a different number without changing the plan for everyone else. The new workspace has its own subscription. That subscription does not hold this limit.
See Manage workspace access and linked workspaces.
Address the linked workspace
tf.api calls run in the workspace where the process is running, unless you name another workspace.
Set tenant_id to the linked workspace on every call that should run there. For tf.api.get, put tenant_id on the query string. For tf.api.post and tf.api.put, put tenant_id in the JSON body. Omit tenant_id when the call should stay in the owner workspace, such as when you write the owner bookkeeping row.
You can pass tenant_id only for a linked workspace in your own workspace group. Any other workspace is rejected. Workspace names are unique across Tealfabric.
Repeat a run safely
Look up existing objects by name and skip what is already there. Running the process again for the same workspace name reuses that linked workspace.
| Object | Lookup |
|---|---|
| Linked workspace | GET /api/v1/workspace-groups/linked-workspaces and match name |
| DataPool schema | GET /api/v1/datapool/schemas?tenant_id=... and match schema_name in data |
| Process | GET /api/v1/processflow?action=processes&search=...&tenant_id=... and match name in data |
| WebApp | GET /api/v1/webapps?search=...&tenant_id=... and match name in webapps |
POST /api/v1/datapool/schemas returns an error when that schema name already exists in the workspace. POST /api/v1/workspace-groups/sibling-workspaces returns Workspace name already exists when the name is taken. Treat both as "look up the existing one and continue."
Example: a recruiting application for each organization
This is one use of the calls above. A form collects an organization name and an email address. The process publishes a recruiting application into a linked workspace of that name. The person who submits the form does not need to be a workspace administrator, and this example does not create a console login for them. pageHtml and stepSource come from the records kept on the owner workspace. Another organization can keep the same call order and change the names, schemas, and files.
1. Reuse or create the linked workspace
const organizationName = String(process_input.organization_name ?? "").trim();
const adminEmail = String(process_input.admin_email ?? "").trim().toLowerCase();
const listed = await tf.api.get("/api/v1/workspace-groups/linked-workspaces");
const existing = (listed.workspaces ?? []).find(
(workspace) => String(workspace.name) === organizationName && !workspace.is_owner
);
let siblingTenantId = existing ? String(existing.tenant_id) : "";
if (!siblingTenantId) {
const created = await tf.api.post("/api/v1/workspace-groups/sibling-workspaces", {
name: organizationName
});
if (!created.success) {
throw new Error(String(created.message ?? "Could not create the linked workspace"));
}
siblingTenantId = String(created.tenant_id);
}
GET returns workspaces (tenant_id, name, status, is_owner), sibling_count, max_linked_workspaces, can_create_sibling, and plan_allows_linked_workspaces. POST returns tenant_id, name, and group_id.
Administrators of the owner workspace are also administrators of the new workspace. Integrations, SSO, API keys, and ProcessFlow keystores stay in the workspace where they were configured. Connect those in the new workspace when that workspace needs them.
2. Create the WebApp service account
A published WebApp needs a service account in the linked workspace. From this process, role must be webapp_user. The email must be unique across Tealfabric. This example derives it from the organization name so it stays separate from the address on the form.
const serviceEmail = `app+${organizationName.toLowerCase().replace(/[^a-z0-9]+/g, "-")}@apps.example.com`;
const user = await tf.api.post("/api/v1/users", {
tenant_id: siblingTenantId,
email: serviceEmail,
full_name: `${organizationName} app`,
role: "webapp_user",
timezone: "UTC"
});
if (!user.success) {
throw new Error(String(user.message ?? "Could not create the WebApp service account"));
}
const webappUserId = String(user.data.user_id);
The response includes data.user_id and temporary_password. The platform also emails that password to serviceEmail, so use an address your organization controls. That account runs the WebApp. See Workspace user roles.
On a repeat run, skip this call when you already stored webapp_user_id for this workspace. Creating the same email again returns An account with this email already exists.
3. Create DataPool schemas and rows
Create the schema, then insert the first row. In this example the row is application data for the recruiting app. It is not a console user.
const schemas = await tf.api.get(
`/api/v1/datapool/schemas?tenant_id=${encodeURIComponent(siblingTenantId)}`
);
const schemaExists = (schemas.data ?? []).some((row) => row.schema_name === "applicants");
if (!schemaExists) {
const schema = await tf.api.post("/api/v1/datapool/schemas", {
tenant_id: siblingTenantId,
schema_name: "applicants",
schema_type: "structured",
storage_backend: "database",
description: "Job applicants",
schema_definition: [
{ name: "email", type: "string" },
{ name: "full_name", type: "string" },
{ name: "status", type: "string" }
]
});
if (!schema.success) {
throw new Error(String(schema.message ?? "Could not create the schema"));
}
}
await tf.api.post("/api/v1/datapool/data", {
tenant_id: siblingTenantId,
schema_name: "applicants",
data: {
email: adminEmail,
full_name: organizationName,
status: "invited"
}
});
tf.datapool.insert writes the workspace where the process is running. Use tf.api with tenant_id when the row belongs in the linked workspace. On the owner workspace, tf.datapool is the right helper for the bookkeeping schema in this example, app_customers. See DataPool user guide.
4. Create the process
process_status must be active. Omitting it leaves the process in draft.
const processes = await tf.api.get(
`/api/v1/processflow?action=processes&search=${encodeURIComponent("Recruiting app")}&tenant_id=${encodeURIComponent(siblingTenantId)}`
);
const existingProcess = (processes.data ?? []).find((row) => row.name === "Recruiting app");
let processId = existingProcess ? String(existingProcess.process_id) : "";
if (!processId) {
const process = await tf.api.post("/api/v1/processflow?action=create", {
tenant_id: siblingTenantId,
name: "Recruiting app",
description: "Handles the recruiting WebApp",
process_status: "active"
});
if (!process.success) {
throw new Error(String(process.message ?? "Could not create the process"));
}
processId = String(process.data.process_id);
const step = await tf.api.post("/api/v1/processflow?action=create-step", {
tenant_id: siblingTenantId,
process_id: processId,
name: "Handle application",
language: "typescript",
sequence: 1,
code_snippet: stepSource
});
if (!step.success) {
throw new Error(String(step.message ?? "Could not create the step"));
}
}
create returns data.process_id. create-step returns data.step_id. Add action=create-flow when one step should call another: send process_id, source_step_id, and target_step_id, plus the same tenant_id.
5. Publish the WebApp and set its public address
const webapps = await tf.api.get(
`/api/v1/webapps?search=${encodeURIComponent("Recruiting")}&tenant_id=${encodeURIComponent(siblingTenantId)}`
);
const existingWebapp = (webapps.webapps ?? []).find((row) => row.name === "Recruiting");
let webappId = existingWebapp ? String(existingWebapp.webapp_id) : "";
if (!webappId) {
const webapp = await tf.api.post("/api/v1/webapps", {
tenant_id: siblingTenantId,
name: "Recruiting",
description: "Customer recruiting application",
type: "webapp",
webapp_user_id: webappUserId,
process_id: processId,
page_content: pageHtml,
auth_transport: "cookie",
auth_require: false
});
if (!webapp.success) {
throw new Error(String(webapp.message ?? webapp.errors?.join("; ") ?? "Could not create the WebApp"));
}
webappId = String(webapp.webapp_id);
const published = await tf.api.post(`/api/v1/webapps/${webappId}/publish`, {
tenant_id: siblingTenantId,
version: 1
});
if (!published.success) {
throw new Error(String(published.message ?? "Could not publish the WebApp"));
}
const address = await tf.api.put(`/api/v1/webapps/${webappId}/versions/1/public-uri`, {
tenant_id: siblingTenantId,
public_uri_host: "northwind.example.com",
public_uri_path: "/recruiting"
});
if (!address.success) {
throw new Error(String(address.message ?? address.errors?.join("; ") ?? "Could not set the public address"));
}
}
Create returns webapp_id. Publish returns message: "Version published successfully". The public-address call returns public_url, host, and path. Host and path together must be unique. The host cannot be app.tealfabric.io. type is one of webapp, webhook, websocket, callback, or document-viewer. See WebApps API documentation.
6. Write text files to the CDN folder
const written = await tf.api.put("/api/v1/documents?action=write-text", {
tenant_id: siblingTenantId,
file_path: "CDN/app/index.html",
content: pageHtml,
encoding: "utf8"
});
if (!written.success) {
throw new Error(String(written.message ?? "Could not write the CDN file"));
}
encoding must be utf8 when you send it. The file is then available at https://cdn.tealfabric.io/t/<linked-workspace-id>/app/index.html. Put only non-sensitive static files in CDN/. See Content Delivery Network.
Images and other binary files use tf.documents.upload. The helper sends base64 JSON to POST /api/v1/documents?action=upload. tenant_id selects the linked workspace. Decoded size is capped at 12 MiB.
const uploaded = await tf.documents.upload({
tenant_id: siblingTenantId,
destination_path: "CDN/app",
filename: "logo.png",
content_base64: logoBase64
});
if (!uploaded.success) {
throw new Error(String(uploaded.message ?? "Could not upload the CDN file"));
}
7. Send the email and record the result
tf.email.send runs in the owner workspace. This example writes the bookkeeping row there as well, with no tenant_id.
const publicUrl = "https://northwind.example.com/recruiting";
await tf.email.send({
to: adminEmail,
subject: `${organizationName} is ready`,
text: `Your application is available at ${publicUrl}`
});
await tf.datapool.insert("app_customers", {
organization_name: organizationName,
admin_email: adminEmail,
sibling_tenant_id: siblingTenantId,
public_url: publicUrl
});
return { success: true, data: { sibling_tenant_id: siblingTenantId, public_url: publicUrl } };
On a repeat run, update the existing bookkeeping row instead of inserting another one.
Limits you will see
| Response | What to do |
|---|---|
| Linked workspaces require a Basic, Premium, or Enterprise subscription on the owner workspace | Move the owner workspace to one of those plans |
Linked workspace limit reached (sibling_count of max_linked_workspaces) | Retire an unused linked workspace, or raise max_linked_workspaces on the owner subscription |
Workspace name already exists | Reuse the workspace returned by the linked-workspaces list |
An account with this email already exists | Use the service account you already created for this workspace |
Invalid role | Send role: "webapp_user" |
Schema already exists | Continue with the existing schema |
| Access denied to this tenant | tenant_id is not a linked workspace of the owner workspace where the process is running |