{"record":{"id":"cdb64f4913f31d1b","repo":"Budibase/budibase","slug":"siteid-is-required","errorCode":null,"errorMessage":"siteId is required","messagePattern":"siteId is required","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/api/controllers/ai/files.ts","lineNumber":319,"sourceCode":"    options: await fetchSharePointSitesByDatasourceAuthConfig(\n      datasourceId,\n      authConfigId\n    ),\n  }\n  ctx.status = 200\n}\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","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/ai/files.ts#L301-L337","documentation":"Thrown by fetchAgentKnowledgeSourceEntries with HTTP 400 when the siteId query parameter is absent or blank. A SharePoint site must be selected before its drive entries can be listed for the operation.","triggerScenarios":"Calling the entries endpoint without ?siteId=; siteId present but only whitespace (trimmed to empty); skipping the site-selection step and jumping straight to folder browsing.","commonSituations":"Deep links to a folder browser without carrying siteId in state; a picker UI that clears siteId on refresh; automated scripts listing entries without choosing a site first.","solutions":["Add a valid siteId query parameter obtained from the site-options endpoint.","Trim and verify query params before building the request URL.","Return the user to the site-selection step when siteId is missing.","Default the UI to the site list when no site has been chosen."],"exampleFix":"// before\nawait api.get(`/ai/agents/${agentId}/operations/${opId}/knowledge-sources/entries?parentPath=${path}`)\n// after\nawait api.get(`/ai/agents/${agentId}/operations/${opId}/knowledge-sources/entries?siteId=${encodeURIComponent(siteId)}&parentPath=${encodeURIComponent(path)}`)","handlingStrategy":"validation","validationCode":"const siteId = new URLSearchParams(query).get(\"siteId\")?.trim()\nif (!siteId) throw new Error(\"siteId is required\")\nawait api.fetchKnowledgeSourceEntries({ agentId, operationId, siteId })","typeGuard":null,"tryCatchPattern":"try {\n  await api.fetchKnowledgeSourceEntries(params)\n} catch (err) {\n  if (err.status === 400 && err.message === \"siteId is required\") {\n    // return user to site-selection step\n  } else throw err\n}","preventionTips":["Select a SharePoint site before browsing entries; keep siteId in picker state.","Trim and verify query params before building the request URL.","Default the UI to the site list when siteId is absent.","Do not rely on parentPath alone to imply a site."],"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"}