{"record":{"id":"a26190d199e0c74d","repo":"Budibase/budibase","slug":"specified-sharepoint-site-is-not-connected-for-thi","errorCode":null,"errorMessage":"Specified SharePoint site is not connected for this operation","messagePattern":"Specified SharePoint site is not connected for this operation","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/api/controllers/ai/files.ts","lineNumber":365,"sourceCode":"  ctx.status = 204\n}\n\nexport async function syncAgentKnowledgeSource(\n  ctx: UserCtx<\n    SyncAgentKnowledgeSourcesRequest,\n    SyncAgentKnowledgeSourcesResponse,\n    { agentId: string; operationId: string; sourceId: string }\n  >\n) {\n  const { agentId, operationId, sourceId } = ctx.params\n  const agent = await sdk.ai.agents.getOrThrow(agentId)\n  const sharePointSources = getSharePointSourcesForOperation(agent, operationId)\n  if (sharePointSources.length === 0) {\n    throw new HTTPError(\"SharePoint is not connected for this operation\", 400)\n  }\n  const source = sharePointSources.find(source => source.id === sourceId)\n  if (!source) {\n    throw new HTTPError(\n      \"Specified SharePoint site is not connected for this operation\",\n      400\n    )\n  }\n\n  console.log(\"Agent knowledge source sync requested\", {\n    agentId,\n    operationId,\n    sourceId,\n  })\n  await sdk.ai.rag.knowledgeSourceSyncQueue.enqueueAgentJobs(\n    agentId,\n    AgentKnowledgeSourceType.SHAREPOINT,\n    [sourceId]\n  )\n  ctx.body = {\n    agentId,\n    sourceId,","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/ai/files.ts#L347-L383","documentation":"Thrown by syncAgentKnowledgeSource with HTTP 400 when SharePoint sources exist for the operation but none matches the sourceId path parameter. The requested site is not among the operation's connected SharePoint sources.","triggerScenarios":"Syncing with a sourceId from a deleted or disconnected SharePoint source; stale client state after the agent was edited; a typo/wrong ID (e.g. from a different agent or operation); case mismatch between stored and requested sourceId.","commonSituations":"Queued jobs or UI rows referencing sources removed by another admin; reusing sourceIds after reconnecting a site (new ID generated); hardcoded sourceIds in scripts.","solutions":["Refresh the agent's source list and sync only IDs present in it.","Remove cached sourceIds after a site is disconnected or the agent is edited.","Verify the sourceId belongs to the same agentId/operationId being called.","Handle this 400 by re-listing sources rather than retrying the same ID."],"exampleFix":"// before\nawait api.syncKnowledgeSource(agentId, operationId, staleSourceId)\n// after\nconst { sources } = await api.listKnowledgeSources(agentId, operationId)\nconst valid = sources.find(s => s.id === sourceId)\nif (valid) await api.syncKnowledgeSource(agentId, operationId, valid.id)","handlingStrategy":"validation","validationCode":"const agent = await api.getAgent(agentId)\nconst src = agent.operations?.find(op => op.id === operationId)?.knowledgeSources?.find(s => s.type === \"sharepoint\" && s.id === sourceId)\nif (!src) throw new Error(\"source \" + sourceId + \" not connected\")\nawait api.syncAgentKnowledgeSource(agentId, operationId, sourceId)","typeGuard":"function sourceIsConnected(agent, operationId, sourceId) {\n  return Boolean(agent?.operations?.some(op => op.id === operationId && op.knowledgeSources?.some(s => s.id === sourceId)))\n}","tryCatchPattern":"try {\n  await api.syncAgentKnowledgeSource(agentId, operationId, sourceId)\n} catch (err) {\n  if (err.status === 400 && err.message.includes(\"Specified SharePoint site is not connected\")) {\n    // refresh the source list and drop the stale sourceId\n  } else throw err\n}","preventionTips":["Refresh the agent's source list before syncing and sync only listed source IDs.","Remove cached sourceIds after a site is disconnected or the agent is edited.","Key UI rows by source.id so only valid sources expose a sync action.","Handle 400 from sync by re-listing sources rather than retrying the same ID."],"tags":["http-400","validation","stale-id","sharepoint"],"backgroundTag":"resource-not-found","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}