hcengineering/platform · error

Accounts URL or token is not defined

Error message

Accounts URL or token is not defined

What it means

getIntegrationClient builds an IntegrationClient for the calendar by reading the Accounts service URL and auth token from metadata. If either is undefined it cannot talk to the accounts service and throws before creating the client.

Source

Thrown at plugins/calendar-resources/src/api.ts:65

export async function disconnect (integration: Integration): Promise<void> {
  const integrationClient = await getIntegrationClient()
  const result = await integrationClient.removeIntegration(integration.socialId, integration.workspaceUuid)
  if (result !== undefined && result.connectionRemoved) {
    await signout(integration, integrationClient)
  }
}

export async function disconnectAll (integration: Integration): Promise<void> {
  const integrationClient = await getIntegrationClient()
  await integrationClient.removeConnection(integration)
  await signout(integration, integrationClient)
}

export async function getIntegrationClient (): Promise<IntegrationClient> {
  const accountsUrl = getMetadata(login.metadata.AccountsUrl)
  const token = getMetadata(presentation.metadata.Token)
  if (accountsUrl === undefined || token === undefined) {
    throw new Error('Accounts URL or token is not defined')
  }
  return getIntegrationClientRaw(accountsUrl, token, calendarIntegrationKind, 'calendar')
}

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Configure login.metadata.AccountsUrl in deployment metadata
  2. Ensure presentation.metadata.Token is available (authenticated context)
  3. In tests/headless code, set the required metadata via setMetadata before calling

Example fix

// before: metadata missing, throws
await getIntegrationClient()
// after: seed metadata first
setMetadata(login.metadata.AccountsUrl, 'https://accounts.example.com')
setMetadata(presentation.metadata.Token, token)
await getIntegrationClient()
Defensive patterns

Strategy: validation

Validate before calling

const accountsUrl = getMetadata(login.metadata.AccountsUrl)
const token = getMetadata(presentation.metadata.Token)
if (accountsUrl === undefined || token === undefined) throw new Error('Calendar integration requires AccountsUrl and token metadata')

Type guard

const canBuildIntegrationClient = (): boolean =>
  getMetadata(login.metadata.AccountsUrl) !== undefined &&
  getMetadata(presentation.metadata.Token) !== undefined

Try / catch

try {
  const client = await getIntegrationClient()
} catch (err) {
  if ((err as Error).message.includes('Accounts URL or token is not defined')) {
    logger.error('Metadata bootstrap incomplete for calendar integration')
  } else throw err
}

Prevention

When it happens

Trigger: Calling getIntegrationClient (via integrationClient factory) when login.metadata.AccountsUrl or presentation.metadata.Token is unset — typically a misconfigured frontend or headless context without login metadata.

Common situations: Self-hosted deployments without AccountsUrl metadata configured; code running outside a logged-in presentation context; environment where accounts service URL changed and metadata not updated; unit tests invoking integration code without metadata bootstrap.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/b77ec4e8fe82771f. Report an issue: GitHub.