{"record":{"id":"827a1e75cb4840a5","repo":"Budibase/budibase","slug":"error-getting-account-by-tenantid-tenantid","errorCode":null,"errorMessage":"Error getting account by tenantId ${tenantId}","messagePattern":"Error getting account by tenantId (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/backend-core/src/accounts/accounts.ts","lineNumber":57,"sourceCode":"\nexport const getAccountByTenantId = async (\n  tenantId: string\n): Promise<CloudAccount | undefined> => {\n  if (EXIT_EARLY) {\n    return\n  }\n  const payload = {\n    tenantId,\n  }\n  const response = await api.post(`/api/accounts/search`, {\n    body: payload,\n    headers: {\n      [Header.API_KEY]: env.ACCOUNT_PORTAL_API_KEY,\n    },\n  })\n\n  if (response.status !== 200) {\n    throw new Error(`Error getting account by tenantId ${tenantId}`)\n  }\n\n  const json: CloudAccount[] = await response.json()\n  return json[0]\n}\n\nexport const getStatus = async (): Promise<\n  HealthStatusResponse | undefined\n> => {\n  if (EXIT_EARLY) {\n    return\n  }\n  const response = await api.get(`/api/status`, {\n    headers: {\n      [Header.API_KEY]: env.ACCOUNT_PORTAL_API_KEY,\n    },\n  })\n  const json = await response.json()","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/backend-core/src/accounts/accounts.ts#L39-L75","documentation":"listSharePointDrives pages through GET /v1.0/sites/{siteId}/drives. If any page returns a non-ok status other than 401/403 (which get a dedicated message), it throws 'Failed to list SharePoint drives (<status>)'. The status code in the message is the raw Microsoft Graph HTTP status after built-in retries of 429/5xx.","triggerScenarios":"fetch to graph.microsoft.com/v1.0/sites/{siteId}/drives?$top=200 returns e.g. 404 (site not found), 400 (bad siteId), or a persistent 5xx/429 after retries.","commonSituations":"Site ID from a previous sync was deleted/renamed in SharePoint; malformed or URL-encoded siteId; transient Graph outages that exhausted the 3-retry budget; tenant throttling beyond Retry-After handling.","solutions":["Check the HTTP status in the message: 404 means the siteId no longer exists — re-select the site so a fresh ID is stored.","Verify the site is still accessible at https://<tenant>.sharepoint.com and its Graph ID via GET /v1.0/sites?search=.","For 429/5xx, wait and retry later; the code already retries 429/500/502/503/504 up to 3 times with backoff.","Confirm the bearer token's scope covers the target site (Sites.Read.All application permission with admin consent)."],"exampleFix":"// before\nawait listSharePointDrives(token, staleSiteId) // 404 -> \"Failed to list SharePoint drives (404)\"\n// after\nconst sites = await fetchSharePointSitesByDatasourceAuthConfig(datasourceId, authConfigId)\nconst current = sites.find(s => s.name === siteName)\nawait listSharePointDrives(token, current.id) // fresh site ID","handlingStrategy":"try-catch","validationCode":"const status = Number(String(err.message).match(/\\((\\d+)\\)$/)?.[1])\nif (status === 404) {\n  // site deleted: refresh the site selection before retrying\n}","typeGuard":"const isSharePointHttpError = (e: unknown): e is { message: string; status: number } =>\n  typeof e === \"object\" && e !== null && \"status\" in e && typeof (e as { status: unknown }).status === \"number\"","tryCatchPattern":"try {\n  const drives = await listSharePointDrives(token, siteId)\n} catch (e) {\n  if (isSharePointHttpError(e) && e.status === 400 && /drives \\(404\\)/.test(e.message)) {\n    // re-resolve site ID, then retry once\n  } else throw e\n}","preventionTips":["Always resolve site IDs freshly from fetchSharePointSitesByDatasourceAuthConfig instead of caching them long-term.","Retry syncs with exponential backoff on 5xx/429 before alerting.","Validate the site still exists in SharePoint admin center when a sync fails.","Use raw Graph site IDs, never site URLs."],"tags":["sharepoint","microsoft-graph","http-404","network"],"backgroundTag":"graph-api-request-failed","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}