{"record":{"id":"19e815856a502f25","repo":"Budibase/budibase","slug":"sharepoint-auth-config-not-found","errorCode":null,"errorMessage":"SharePoint auth config not found.","messagePattern":"SharePoint auth config not found\\.","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/sdk/workspace/ai/knowledgeSources/sharepoint/connection.ts","lineNumber":168,"sourceCode":"      nextUrl.hostname === SHAREPOINT_API_BASE_URL.hostname &&\n      nextUrl.port === SHAREPOINT_API_BASE_URL.port &&\n      (nextUrl.pathname === SHAREPOINT_API_BASE_URL.pathname ||\n        nextUrl.pathname.startsWith(`${SHAREPOINT_API_BASE_URL.pathname}/`))\n    )\n  } catch {\n    return false\n  }\n}\n\nconst readConnection = async (\n  datasourceId: string,\n  authConfigId: string\n): Promise<OAuth2RestAuthConfigWithTokenCache> => {\n  let datasource: Datasource\n  try {\n    datasource = await sdk.datasources.get(datasourceId)\n  } catch {\n    throw new HTTPError(\"SharePoint auth config not found.\", 400)\n  }\n  const authConfigs = datasource.config?.authConfigs as\n    | OAuth2RestAuthConfigWithTokenCache[]\n    | undefined\n  const authConfig = authConfigs?.find(config => config._id === authConfigId)\n  if (!authConfig) {\n    throw new HTTPError(\"SharePoint auth config not found.\", 400)\n  }\n  if (!isOAuth2ClientCredentialsAuthConfig(authConfig)) {\n    throw new HTTPError(\n      \"SharePoint requires an OAuth2 client credentials auth config.\",\n      400\n    )\n  }\n  if (!authConfig.url || !authConfig.clientId) {\n    throw new HTTPError(\n      \"OAuth2 auth config is missing token URL or client ID.\",\n      400","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/ai/knowledgeSources/sharepoint/connection.ts#L150-L186","documentation":"readConnection loads the SharePoint datasource and locates the OAuth2 auth config by id. If sdk.datasources.get throws (datasource does not exist, deleted, or DB error), the error is swallowed and re-thrown as 'SharePoint auth config not found.' with status 400. Note this same message covers the datasource-not-found case, not just a missing auth config.","triggerScenarios":"Calling connection()/getSharePointBearerToken()/fetchSharePointSitesByDatasourceAuthConfig with a datasourceId that no longer exists, or an authConfigId that is not present in datasource.config.authConfigs.","commonSituations":"The REST datasource was deleted or its auth config removed while a SharePoint knowledge source still references the ids; copying a knowledge source between apps; stale authConfigId after the datasource was re-configured.","solutions":["Verify the datasourceId exists in the workspace (datasources API) and has not been deleted.","Check datasource.config.authConfigs contains an entry whose _id equals the authConfigId being used.","Re-link the SharePoint knowledge source to a current datasource + auth config pair."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const datasource = await sdk.datasources.get(datasourceId) // throws if missing\nconst authConfig = datasource.config?.authConfigs?.find(c => c._id === authConfigId)\nif (!authConfig) {\n  throw new Error(`Auth config ${authConfigId} missing on datasource ${datasourceId}`)\n}","typeGuard":null,"tryCatchPattern":"try {\n  await fetchSharePointSitesByDatasourceAuthConfig(datasourceId, authConfigId)\n} catch (err) {\n  if (err instanceof HTTPError && err.message === \"SharePoint auth config not found.\") {\n    // prompt user to re-configure the SharePoint datasource/auth config\n  }\n  throw err\n}","preventionTips":["When deleting a datasource, also delete or re-link any SharePoint knowledge sources referencing it.","Store datasourceId + authConfigId together and validate the pair exists before saving a knowledge source.","Avoid copying knowledge source configs between apps where ids do not resolve."],"tags":["sharepoint","oauth2","missing-config","http-400"],"backgroundTag":"auth-config-not-found","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}