{"record":{"id":"491585c773173535","repo":"Budibase/budibase","slug":"sharepoint-site-is-not-connected-for-this-operatio","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/api/controllers/ai/files.ts","lineNumber":512,"sourceCode":"  )\n  ctx.status = 200\n}\n\nexport async function updateAgentSharePointSite(\n  ctx: UserCtx<\n    UpdateAgentSharePointSiteRequest,\n    UpdateAgentSharePointSiteResponse,\n    { agentId: string; operationId: string; siteId: string }\n  >\n) {\n  const { agentId, operationId, siteId } = ctx.params\n  const existingAgent = await sdk.ai.agents.getOrThrow(agentId)\n  const source = getSharePointSourcesForOperation(\n    existingAgent,\n    operationId\n  ).find(source => source.config.site.id === siteId)\n  if (!source) {\n    throw new HTTPError(\n      \"SharePoint site is not connected for this operation\",\n      404\n    )\n  }\n\n  const { scope } = ctx.request.body\n  const updated = await sdk.ai.agents.update({\n    ...existingAgent,\n    operations: updateOperationKnowledgeSources(\n      existingAgent,\n      operationId,\n      sources => {\n        const nonSharePointSources = sources.filter(\n          source => source.type !== AgentKnowledgeSourceType.SHAREPOINT\n        )\n        const sharePointSources = sources\n          .filter(source => source.type === AgentKnowledgeSourceType.SHAREPOINT)\n          .map(existingSource =>","sourceCodeStart":494,"sourceCodeEnd":530,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/ai/files.ts#L494-L530","documentation":"Thrown by updateAgentSharePointSite when no existing SharePoint source on the agent for the given operationId matches the supplied siteId. The controller looks up the agent, filters its SharePoint sources by operation, then finds the one whose config.site.id equals the request's siteId; a 404 is raised if none match.","triggerScenarios":"Calling the agent SharePoint site update endpoint with an operationId that has no connected SharePoint sources, a siteId that was never connected, or a siteId connected under a different operation.","commonSituations":"Site was disconnected earlier; client caches a stale siteId after an agent config change; wrong operationId in the URL path; agent was recreated so old source references no longer exist.","solutions":["List the agent's connected SharePoint sources for the operation first and use one of the returned site ids.","Verify the operationId in the path matches the operation the site was originally connected to.","Re-connect the site via the connect endpoint before attempting to update it."],"exampleFix":"// before\nawait api.put(`/ai/agents/${agentId}/operations/${opId}/sharepoint/${staleSiteId}`, { scope: 'items' })\n// after\nconst sources = await getAgentSharePointSources(agentId, opId)\nawait api.put(`/ai/agents/${agentId}/operations/${opId}/sharepoint/${sources[0].config.site.id}`, { scope: 'items' })","handlingStrategy":"validation","validationCode":"const sources = await getAgentSharePointSources(agentId, operationId)\nconst site = sources.find(s => s.config.site.id === siteId)\nif (!site) throw new Error(`Site ${siteId} is not connected to operation ${operationId}`)","typeGuard":"function findConnectedSource(sources: SharePointSource[], siteId: string): SharePointSource | undefined {\n  return sources.find(s => typeof s.config?.site?.id === 'string' && s.config.site.id === siteId)\n}","tryCatchPattern":"try {\n  await updateAgentSharePointSite({ agentId, operationId, siteId, scope })\n} catch (e) {\n  if (e instanceof HTTPError && e.status === 404) {\n    // refresh agent config / re-connect site before updating\n  } else throw e\n}","preventionTips":["Fetch current connected sources before any update or disconnect call.","Keep operationId and siteId together in client state so they never desync.","Re-fetch agent config after any mutation instead of caching site ids."],"tags":["http","sharepoint","not-found","agent-config"],"backgroundTag":"resource-not-found","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}