Budibase/budibase · error · HTTPError

Specified SharePoint site is not connected for this agent

Error message

Specified SharePoint site is not connected for this agent

What it means

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.

Source

Thrown at packages/server/src/sdk/workspace/ai/rag/sources/sharepoint/sharepoint.ts:1355

          abortController.signal
        )
      } finally {
        clearTimeout(timeout)
      }
    }
  )

  return result
}

export const syncSharePointSourcesForAgent = async (
  agentId: string,
  sourceId: string
): Promise<SharePointSyncResult> => {
  const agent = await agentsSdk.getOrThrow(agentId)
  const operationId = findOperationIdForKnowledgeSource(agent, sourceId)
  if (!operationId) {
    throw new HTTPError(
      "Specified SharePoint site is not connected for this agent",
      400
    )
  }

  return await syncSharePointSourcesForOperation(agentId, operationId, sourceId)
}

export const deleteSharePointFilesForOperationSite = async (
  agentId: string,
  operationId: string,
  siteId: string
) => {
  const files = await listFilesForOperation(agentId, operationId)
  const fileIdsToDelete = files
    .filter(
      file =>
        (file.source?.type === KnowledgeBaseFileSourceType.SHAREPOINT_SITE ||

View on GitHub (pinned to a81a902e9a)

Solutions

  1. List the agent's knowledge sources and use a valid sourceId that is attached to an operation
  2. Re-add the SharePoint source to the agent if it was deleted, then sync the new sourceId
  3. Confirm you are calling the sync for the correct agentId that owns the source
  4. Refresh UI/client state so it reflects the agent's current sources

Example fix

// before
await syncSharePointSourceForAgent(agentId, staleSourceId)
// after
const agent = await agentsSdk.getOrThrow(agentId)
const validId = agent.operations.flatMap(o => o.knowledgeSources ?? []).find(s => s.type === "sharepoint")?.id
if (validId) await syncSharePointSourceForAgent(agentId, validId)
Defensive patterns

Strategy: validation

Validate before calling

const agent = await agentsSdk.getOrThrow(agentId)
const opId = findOperationIdForKnowledgeSource(agent, sourceId)
if (!opId) {
  throw new Error(`Source ${sourceId} is not attached to any operation on agent ${agentId}`)
}

Type guard

const isSourceOnAgent = (agent: Agent, sourceId: string): boolean =>
  findOperationIdForKnowledgeSource(agent, sourceId) !== null

Try / catch

try {
  await syncSharePointSourceForAgent(agentId, sourceId)
} catch (err) {
  if (err instanceof HTTPError && err.status === 400 && err.message.includes("not connected for this agent")) {
    // refresh source list and pick a valid sourceId
  } else { throw err }
}

Prevention

When it happens

Trigger: 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).

Common situations: Client cached a sourceId after the source was deleted; copying sourceIds between agents; typo/stale id stored in UI state; agent document updated concurrently.

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/1cf4b595d9b1de33. Report an issue: GitHub.