{"record":{"id":"80b1b2a16eca78d3","repo":"Mintplex-Labs/anything-llm","slug":"addtoworkspaces-must-be-a-string-of-comma-separate","errorCode":null,"errorMessage":"addToWorkspaces must be a string of comma-separated workspace slugs. Got ${typeof addToWorkspaces}","messagePattern":"addToWorkspaces must be a string of comma-separated workspace slugs\\. Got (.+?)","errorType":"http","errorClass":null,"httpStatus":422,"severity":"warning","filePath":"server/endpoints/api/document/index.js","lineNumber":37,"sourceCode":"const createFilesLib = require(\"../../../utils/agents/aibitat/plugins/create-files/lib\");\nconst documentsPath =\n  process.env.NODE_ENV === \"development\"\n    ? path.resolve(__dirname, \"../../../storage/documents\")\n    : path.resolve(process.env.STORAGE_DIR, `documents`);\n\n/**\n * Runs a simple validation check on the addToWorkspaces query parameter to ensure it is a string of comma-separated workspace slugs.\n * @param {*} request\n * @param {*} response\n * @param {*} next\n * @returns\n */\nfunction validateWorkspaceSlugQuery(request, response, next) {\n  const { addToWorkspaces = \"\" } = reqBody(request);\n  if (!addToWorkspaces) return next();\n  if (typeof addToWorkspaces !== \"string\") {\n    return response\n      .status(422)\n      .json({\n        success: false,\n        error: `addToWorkspaces must be a string of comma-separated workspace slugs. Got ${typeof addToWorkspaces}`,\n      })\n      .end();\n  }\n  next();\n}\n\nfunction apiDocumentEndpoints(app) {\n  if (!app) return;\n\n  app.post(\n    \"/v1/document/upload\",\n    [validApiKey, handleAPIFileUpload, validateWorkspaceSlugQuery],\n    async (request, response) => {\n      /*\n    #swagger.tags = ['Documents']","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/endpoints/api/document/index.js#L19-L55","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (axios -> addToWorkspaces[]=a&addToWorkspaces[]=b)\naxios.post(url, formData, { params: { addToWorkspaces: ['a','b'] } });\n\n// after\naxios.post(url, formData, { params: { addToWorkspaces: ['a','b'].join(',') } });","handlingStrategy":"validation","validationCode":"function buildUploadParams(slugs) {\n  const v = Array.isArray(slugs) ? slugs.join(',') : slugs;\n  if (typeof v !== 'string') throw new TypeError('addToWorkspaces must be a comma-separated string');\n  return v ? { addToWorkspaces: v } : {}; // omit entirely when empty\n}","typeGuard":"function isAddToWorkspacesParam(v) {\n  return v == null || v === '' || typeof v === 'string';\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["document-api","http-422","query-parameters","validation"],"backgroundTag":"query-param-validation","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}