{"record":{"id":"f976a1d419cc5bcb","repo":"Budibase/budibase","slug":"driveid-is-required-with-parentitemid","errorCode":null,"errorMessage":"driveId is required with parentItemId","messagePattern":"driveId is required with parentItemId","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/api/controllers/ai/files.ts","lineNumber":325,"sourceCode":"}\n\nexport async function fetchAgentKnowledgeSourceEntries(\n  ctx: UserCtx<\n    void,\n    FetchAgentKnowledgeSourceEntriesResponse,\n    { agentId: string; operationId: string }\n  >\n) {\n  const { agentId, operationId } = ctx.params\n  const siteId = String(ctx.query.siteId || \"\").trim()\n  if (!siteId) {\n    throw new HTTPError(\"siteId is required\", 400)\n  }\n  const driveId = String(ctx.query.driveId || \"\").trim() || undefined\n  const parentItemId = String(ctx.query.parentItemId || \"\").trim() || undefined\n  const parentPath = String(ctx.query.parentPath || \"\").trim()\n  if (parentItemId && !driveId) {\n    throw new HTTPError(\"driveId is required with parentItemId\", 400)\n  }\n  ctx.body = await sdk.ai.rag.fetchSharePointEntriesForOperation(\n    agentId,\n    operationId,\n    siteId,\n    driveId,\n    parentItemId,\n    parentPath\n  )\n  ctx.status = 200\n}\n\nexport async function resetAgentKnowledgeBaseStore(\n  ctx: UserCtx<void, void, { agentId: string; operationId: string }>\n) {\n  const { agentId, operationId } = ctx.params\n  const knowledgeBase = await sdk.ai.rag.ensureKnowledgeBaseForOperation(\n    agentId,","sourceCodeStart":307,"sourceCodeEnd":343,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/ai/files.ts#L307-L343","documentation":"Thrown by fetchAgentKnowledgeSourceEntries with HTTP 400 when parentItemId is supplied without driveId. Listing children of a SharePoint item requires knowing which drive the item belongs to.","triggerScenarios":"Browsing into a folder (parentItemId set) after losing the driveId query param; navigation state that tracks parentItemId but drops driveId; bookmarks/links built with incomplete query params.","commonSituations":"Picker UIs where drive selection is optional but folder browsing is attempted anyway; stale browser back/forward entries missing driveId; scripts paginating with parentItemId only.","solutions":["Always include driveId in the query when parentItemId is provided.","Keep site/drive/folder selection state together in the picker UI.","Clear parentItemId whenever driveId changes to avoid inconsistent requests.","Add client-side validation mirroring the server's parentItemId+driveId rule."],"exampleFix":"// before\nconst qs = new URLSearchParams({ siteId, parentItemId })\n// after\nconst qs = new URLSearchParams({ siteId, parentItemId })\nif (parentItemId) qs.set(\"driveId\", driveId)","handlingStrategy":"validation","validationCode":"if (parentItemId && !driveId) throw new Error(\"driveId is required with parentItemId\")\nawait api.fetchKnowledgeSourceEntries({ agentId, operationId, siteId, driveId, parentItemId })","typeGuard":null,"tryCatchPattern":"try {\n  await api.fetchKnowledgeSourceEntries(params)\n} catch (err) {\n  if (err.status === 400 && err.message.includes(\"driveId is required\")) {\n    // fall back to drive listing or reselect drive\n  } else throw err\n}","preventionTips":["Always carry driveId forward once a drive is selected; include it with every nested-item request.","Track site/drive/folder selection state together, not independently.","Clear parentItemId when driveId changes.","Add client-side validation mirroring the server's parentItemId+driveId rule."],"tags":["http-400","validation","missing-parameter","sharepoint"],"backgroundTag":"missing-required-parameter","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}