{"record":{"id":"1cf4b595d9b1de33","repo":"Budibase/budibase","slug":"specified-sharepoint-site-is-not-connected-for-thi-1cf4b5","errorCode":null,"errorMessage":"Specified SharePoint site is not connected for this agent","messagePattern":"Specified SharePoint site is not connected for this agent","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/rag/sources/sharepoint/sharepoint.ts","lineNumber":1355,"sourceCode":"          abortController.signal\n        )\n      } finally {\n        clearTimeout(timeout)\n      }\n    }\n  )\n\n  return result\n}\n\nexport const syncSharePointSourcesForAgent = async (\n  agentId: string,\n  sourceId: string\n): Promise<SharePointSyncResult> => {\n  const agent = await agentsSdk.getOrThrow(agentId)\n  const operationId = findOperationIdForKnowledgeSource(agent, sourceId)\n  if (!operationId) {\n    throw new HTTPError(\n      \"Specified SharePoint site is not connected for this agent\",\n      400\n    )\n  }\n\n  return await syncSharePointSourcesForOperation(agentId, operationId, sourceId)\n}\n\nexport const deleteSharePointFilesForOperationSite = async (\n  agentId: string,\n  operationId: string,\n  siteId: string\n) => {\n  const files = await listFilesForOperation(agentId, operationId)\n  const fileIdsToDelete = files\n    .filter(\n      file =>\n        (file.source?.type === KnowledgeBaseFileSourceType.SHAREPOINT_SITE ||","sourceCodeStart":1337,"sourceCodeEnd":1373,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/rag/sources/sharepoint/sharepoint.ts#L1337-L1373","documentation":"syncSharePointSourceForAgent (agent-level entry point) resolves which operation of the agent owns the given sourceId using findOperationIdForKnowledgeSource. If no operation references that sourceId, this 400 HTTPError is thrown — the agent has no SharePoint knowledge source with that id.","triggerScenarios":"Calling the per-agent sync API with a sourceId that is not attached to any operation on the agent (wrong id, deleted source, or sourceId from a different agent).","commonSituations":"Client cached a sourceId after the source was deleted; copying sourceIds between agents; typo/stale id stored in UI state; agent document updated concurrently.","solutions":["List the agent's knowledge sources and use a valid sourceId that is attached to an operation","Re-add the SharePoint source to the agent if it was deleted, then sync the new sourceId","Confirm you are calling the sync for the correct agentId that owns the source","Refresh UI/client state so it reflects the agent's current sources"],"exampleFix":"// before\nawait syncSharePointSourceForAgent(agentId, staleSourceId)\n// after\nconst agent = await agentsSdk.getOrThrow(agentId)\nconst validId = agent.operations.flatMap(o => o.knowledgeSources ?? []).find(s => s.type === \"sharepoint\")?.id\nif (validId) await syncSharePointSourceForAgent(agentId, validId)","handlingStrategy":"validation","validationCode":"const agent = await agentsSdk.getOrThrow(agentId)\nconst opId = findOperationIdForKnowledgeSource(agent, sourceId)\nif (!opId) {\n  throw new Error(`Source ${sourceId} is not attached to any operation on agent ${agentId}`)\n}","typeGuard":"const isSourceOnAgent = (agent: Agent, sourceId: string): boolean =>\n  findOperationIdForKnowledgeSource(agent, sourceId) !== null","tryCatchPattern":"try {\n  await syncSharePointSourceForAgent(agentId, sourceId)\n} catch (err) {\n  if (err instanceof HTTPError && err.status === 400 && err.message.includes(\"not connected for this agent\")) {\n    // refresh source list and pick a valid sourceId\n  } else { throw err }\n}","preventionTips":["Fetch the agent's current source list before syncing; never use cached sourceIds","Scope UI state per agent so ids cannot cross over","Handle source deletion events by invalidating stored ids","Confirm agentId and sourceId pairing in client calls"],"tags":["sharepoint","sync","lookup-failed"],"backgroundTag":"referenced-resource-missing","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}