Mintplex-Labs/anything-llm · warning
addToWorkspaces must be a string of comma-separated workspac
Error message
addToWorkspaces must be a string of comma-separated workspace slugs. Got ${typeof addToWorkspaces} What it means
validateWorkspaceSlugQuery is an Express middleware on the document-upload API that inspects the `addToWorkspaces` field (via reqBody, i.e. query string or JSON body) and rejects non-string values with 422. The field must be a single comma-separated string of slugs ('ws1,ws2'). Repeated query parameters (addToWorkspaces=a&addToWorkspaces=b) make Express parse an array, and arrays/objects in a JSON body fail the typeof check.
Source
Thrown at server/endpoints/api/document/index.js:37
const createFilesLib = require("../../../utils/agents/aibitat/plugins/create-files/lib");
const documentsPath =
process.env.NODE_ENV === "development"
? path.resolve(__dirname, "../../../storage/documents")
: path.resolve(process.env.STORAGE_DIR, `documents`);
/**
* Runs a simple validation check on the addToWorkspaces query parameter to ensure it is a string of comma-separated workspace slugs.
* @param {*} request
* @param {*} response
* @param {*} next
* @returns
*/
function validateWorkspaceSlugQuery(request, response, next) {
const { addToWorkspaces = "" } = reqBody(request);
if (!addToWorkspaces) return next();
if (typeof addToWorkspaces !== "string") {
return response
.status(422)
.json({
success: false,
error: `addToWorkspaces must be a string of comma-separated workspace slugs. Got ${typeof addToWorkspaces}`,
})
.end();
}
next();
}
function apiDocumentEndpoints(app) {
if (!app) return;
app.post(
"/v1/document/upload",
[validApiKey, handleAPIFileUpload, validateWorkspaceSlugQuery],
async (request, response) => {
/*
#swagger.tags = ['Documents']View on GitHub (pinned to 3aec848f28)
Solutions
- Send one string: ?addToWorkspaces=workspace1,workspace2 (comma-joined, no array syntax)
- Configure your HTTP client's array serializer to produce a single joined string for this parameter
- Omit the parameter entirely when you do not want the document embedded into workspaces — empty is allowed and skips validation
Example fix
// before (axios -> addToWorkspaces[]=a&addToWorkspaces[]=b)
axios.post(url, formData, { params: { addToWorkspaces: ['a','b'] } });
// after
axios.post(url, formData, { params: { addToWorkspaces: ['a','b'].join(',') } }); Defensive patterns
Strategy: validation
Validate before calling
function buildUploadParams(slugs) {
const v = Array.isArray(slugs) ? slugs.join(',') : slugs;
if (typeof v !== 'string') throw new TypeError('addToWorkspaces must be a comma-separated string');
return v ? { addToWorkspaces: v } : {}; // omit entirely when empty
} Type guard
function isAddToWorkspacesParam(v) {
return v == null || v === '' || typeof v === 'string';
} Prevention
- Join slug arrays into one comma-separated string before sending
- Configure HTTP clients (axios paramsSerializer, jQuery $.param traditional mode) to avoid repeated-key array serialization
- Omit addToWorkspaces when no workspace embedding is wanted — empty values bypass the check
When it happens
Trigger: Uploading with query ?addToWorkspaces[]=a&addToWorkspaces[]=b (array); sending addToWorkspaces as a JSON array ['a','b'] in the body; a form serializer emitting repeated keys; multipart metadata carrying an object under that key.
Common situations: Client libraries that auto-serialize arrays as repeated query params (axios with paramsSerializer, jQuery $.param); OpenAPI-generated clients typing the field as array per a stale spec.
Related errors
- click requires <x> <y> coordinates
- type requires <text> argument
- key requires <key> argument (e.g. Enter, Tab, Escape)
- Invalid path name
- Invalid folder name.
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/80b1b2a16eca78d3.
Report an issue: GitHub.