Budibase/budibase · error · HTTPError

workspaceId is required

Error message

workspaceId is required

What it means

Thrown by publishSlackIntegrationForLiveAgent when a Slack-enabled live agent is being published but no workspace ID is present in the request context. The function needs the workspace to look up the production (published) workspace and check the Slack integration; without context.getWorkspaceId() it cannot proceed and throws this 400 error.

Source

Thrown at packages/server/src/api/controllers/ai/agents.ts:216

  return await context.doInWorkspaceContext(prodWorkspaceId, async () => {
    const prodAgent = await context.getWorkspaceDB().tryGet<Agent>(agentId)
    if (!prodAgent) {
      return undefined
    }

    return await configureSlackAppCreationDeployment(agentId)
  })
}

const publishSlackIntegrationForLiveAgent = async (agent: Agent) => {
  if (!agent.live || !agent._id || !agent.slackIntegration) {
    return
  }

  const workspaceId = context.getWorkspaceId()
  if (!workspaceId) {
    throw new HTTPError("workspaceId is required", 400)
  }

  const prodWorkspaceId = db.getProdWorkspaceID(workspaceId)
  const isPublished = await sdk.workspaces.isWorkspacePublished(prodWorkspaceId)
  if (!isPublished) {
    return
  }

  await context.doInWorkspaceContext(prodWorkspaceId, async () => {
    const prodAgent = await context.getWorkspaceDB().tryGet<Agent>(agent._id!)
    if (!prodAgent) {
      return
    }

    const { messagingEndpointUrl } = await configureSlackAppCreationDeployment(
      agent._id!
    )

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Ensure the request carries proper workspace identification (appId/workspace headers or auth context)
  2. Complete the Slack OAuth through the standard UI flow rather than a bare request
  3. Check that authentication middleware ran and populated the tenancy context before this handler
  4. In tests/scripts, set up the workspace context (e.g. context.withWorkspace / doInWorkspace) before invoking

Example fix

// before
await fetch("/api/ai/agents/slack/oauth/complete") // no workspace context
// after
await fetch("/api/ai/agents/slack/oauth/complete", {
  headers: { "x-budibase-app-id": appId },
  credentials: "include"
})
Defensive patterns

Strategy: try-catch

Validate before calling

import { context } from "@budibase/backend-core"
function assertWorkspaceContext() {
  const workspaceId = context.getWorkspaceId()
  if (!workspaceId) {
    throw new Error("workspaceId is required: run this inside a workspace-scoped context")
  }
  return workspaceId
}
assertWorkspaceContext()

Type guard

function hasWorkspaceContext(ctx) {
  return typeof ctx?.getWorkspaceId === "function" && !!ctx.getWorkspaceId()
}

Try / catch

try {
  await completeSlackOAuth(ctx)
} catch (err) {
  if (err.status === 400 && err.message === "workspaceId is required") {
    throw new Error("Slack OAuth completion requires an authenticated, workspace-scoped request")
  }
  throw err
}

Prevention

When it happens

Trigger: Calling completeSlackOAuth (or the Slack publish flow) from a context lacking a workspace — e.g. a request missing the workspace/appId headers or cookies that identify the tenant, or a background/global operation executed outside a workspace-scoped context.

Common situations: Scripts or integrations calling the endpoint without authentication/tenant headers; tests invoking the controller directly without setting up context; session expiry stripping workspace identity; calling the OAuth completion route outside the normal builder/app request flow.

Related errors


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