API Docs
Workspaces Model
Add Workspace
12min
This endpoint allows you to create a new workspace by sending a POST request. The request body contains workspace details such as name, workspace type, plan ID, and optional logo images.
POST https://admin.<your-site>.com/api/workspaces/add
- accept: application/json Specifies that the request expects a JSON response.
- authorization: Bearer <JWT Token> A JSON Web Token (JWT) that authenticates the request. Replace <JWT Token> with a valid token.
- content-type: multipart/form-data; boundary=<boundary> Specifies that the request body is in multipart/form-data format, necessary for file uploads.
The request body should be in multipart/form-data format, containing the following fields:
- name: string The name of the workspace.
- workspace_type: string The type of workspace (e.g., "IFRAME_EMBED", "JWT_FULL_EMBED").
- plan_id: string (Optional) The ID of the plan to associate with the workspace.
- square_logo: file (Optional) A square logo image file for the workspace. Must be less than 10MB.
- image_logo: file (Optional) A logo image file for the workspace. Must be less than 10MB.
- integrations: string (Optional) A JSON string containing integration configurations for the workspace.
{
"name": "Finance Department",
"workspace_type": "IFRAME_EMBED",
"plan_id": "678e56b778bd25203b900e63",
"square_logo": "[Binary file data]",
"image_logo": "[Binary file data]",
"integrations": "[]"
}
Note: For multipart/form-data requests with file uploads, the actual request body will be formatted differently, with binary file content included.
- POST: Sends a request to create a new workspace with the specified details.
const fetch = require('node-fetch');
const FormData = require('form-data');
const fs = require('fs');
const url = 'https://admin.<your-site>.com/api/workspaces/add';
const form = new FormData();
// Add text fields
form.append('name', 'Finance Department');
form.append('workspace_type', 'IFRAME_EMBED');
form.append('plan_id', '678e56b778bd25203b900e63');
form.append('integrations', '[]');
// Add files if available
if (fs.existsSync('./finance_square_logo.png')) {
form.append('square_logo', fs.createReadStream('./finance_square_logo.png'));
}
if (fs.existsSync('./finance_logo.png')) {
form.append('image_logo', fs.createReadStream('./finance_logo.png'));
}
const options = {
method: 'POST',
headers: {
'accept': 'application/json',
'authorization': 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',
// No need to set content-type as form-data sets it automatically with boundary
},
body: form
};
fetch(url, options)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
The API will return a JSON response indicating the success or failure of the operation.
{
"status": 200,
"data": {
"workspace_id": "6812cf45a9b33e12456789ab"
},
"message": "Workspace successfully added."
}
{
"status": 400,
"message": "File size must be less than 10MB."
}
Or:
{
"status": 400,
"message": "Name is required."
}
This API requires a valid JWT token for authentication and admin privileges. Ensure that the token is included in the authorization header as Bearer <JWT Token>.
- This endpoint requires admin privileges to use.
- The system automatically generates a unique slug from the workspace name.
- If no plan_id is provided, the system assigns a free (no charge) plan.
- Logo files must be less than 10MB in size.
- When creating a JWT_FULL_EMBED workspace type, the layout_type is automatically set to NO_NAVIGATION.
- For other workspace types, the layout_type defaults to LEFT_NAVIGATION.
- The system automatically creates subscription and transaction records based on the selected plan.
- If integrations are provided, the system will create workspace integration credentials for each integration.
- The system logs workspace creation in the activity log.