{"record":{"id":"0315ac74748652d7","repo":"Budibase/budibase","slug":"sharepoint-site-is-not-connected-for-this-operatio-0315ac","errorCode":null,"errorMessage":"SharePoint site is not connected for this operation","messagePattern":"SharePoint site is not connected for this operation","errorType":"http","errorClass":"HTTPError","httpStatus":404,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/rag/sources/sharepoint/sharepoint.ts","lineNumber":410,"sourceCode":"  }\n\n  return false\n}\n\nexport const fetchSharePointEntriesForOperation = async (\n  agentId: string,\n  operationId: string,\n  siteId: string,\n  driveId?: string,\n  parentItemId?: string,\n  parentPath = \"\"\n): Promise<FetchAgentKnowledgeSourceEntriesResponse> => {\n  const agent = await agentsSdk.getOrThrow(agentId)\n  const source = getSharePointSourcesForOperation(agent, operationId).find(\n    source => source.config.site.id === siteId\n  )\n  if (!source) {\n    throw new HTTPError(\n      \"SharePoint site is not connected for this operation\",\n      404\n    )\n  }\n\n  const { datasourceId, authConfigId } = source.config\n  if (!datasourceId || !authConfigId) {\n    throw new HTTPError(\"SharePoint is not connected for this workspace\", 400)\n  }\n  const bearerToken = await getSharePointBearerToken(datasourceId, authConfigId)\n  const drives = await listSharePointDrives(bearerToken, siteId)\n  if (!driveId) {\n    const lists = await listSharePointLists(bearerToken, siteId)\n    return {\n      entries: [\n        ...drives.map(\n          (drive): KnowledgeSourceEntry => ({\n            id: `drive:${drive.id}`,","sourceCodeStart":392,"sourceCodeEnd":428,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/rag/sources/sharepoint/sharepoint.ts#L392-L428","documentation":"Thrown by fetchSharePointEntriesForOperation when no SharePoint source on the specified operation matches the given siteId. The site is treated as not connected, so its entries cannot be fetched.","triggerScenarios":"Calling fetchSharePointEntriesForOperation with a siteId that is not in the operation's knowledgeSources SharePoint configs, or using an operation that has no SharePoint sources at all.","commonSituations":"Site disconnected through the UI while a client still holds its id, wrong siteId casing/format, or querying against the wrong operation.","solutions":["Re-fetch the connected SharePoint sites for the operation and use a valid siteId","Reconnect the SharePoint site to the operation before fetching entries","Confirm the operationId and siteId pair match the agent's current knowledge source config"],"exampleFix":"// before\nawait fetchSharePointEntriesForOperation({ agentId, operationId, siteId: removedSiteId }) // 404\n// after\nconst agent = await agentsSdk.getOrThrow(agentId)\nconst sites = (agent.operations?.find(op => op.id === operationId)?.knowledgeSources || [])\n  .filter(s => s.type === 'sharepoint')\nif (!sites.some(s => s.config.site.id === siteId)) {\n  throw new Error(`Site ${siteId} is not connected; reconnect it first`)\n}\nawait fetchSharePointEntriesForOperation({ agentId, operationId, siteId })","handlingStrategy":"validation","validationCode":"const agent = await agentsSdk.getOrThrow(agentId)\nconst connected = (agent.operations?.find(o => o.id === operationId)?.knowledgeSources || [])\n  .some(s => s.config?.site?.id === siteId)\nif (!connected) throw new Error(`Site ${siteId} is not connected to operation ${operationId}`)","typeGuard":"const isSiteConnected = (agent: Agent, operationId: string, siteId: string): boolean =>\n  (agent.operations?.find(o => o.id === operationId)?.knowledgeSources || [])\n    .some(s => s.config?.site?.id === siteId)","tryCatchPattern":"try {\n  const entries = await fetchSharePointEntriesForOperation({ agentId, operationId, siteId })\n} catch (err) {\n  if (err instanceof HTTPError && err.status === 404) {\n    // site disconnected - offer the user a reconnect flow\n  } else throw err\n}","preventionTips":["Sync client-side site lists whenever knowledge sources change","Handle site disconnects in the UI by invalidating cached siteIds","Validate siteId against the operation's sources before fetching entries"],"tags":["sharepoint","not-found","configuration"],"backgroundTag":"sharepoint-site-not-connected","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}