FlowiseAI/Flowise · error · InternalFlowiseError

Error: chatflowsController.saveChatflow - organization ${org

Error message

Error: chatflowsController.saveChatflow - organization ${orgId} not found!

What it means

Thrown by saveChatflow when req.user?.activeOrganizationId is absent (after the body check). Returns 404 NOT_FOUND — misleading code; the missing value is an auth-context field. Indicates the session/token has no org claim.

Source

Thrown at packages/server/src/controllers/chatflows/index.ts:153

                StatusCodes.NOT_FOUND,
                `Error: chatflowsController.getChatflowById - workspace ${workspaceId} not found!`
            )
        }
        const apiResponse = await chatflowsService.getChatflowById(req.params.id, workspaceId)
        return res.json(apiResponse)
    } catch (error) {
        next(error)
    }
}

const saveChatflow = async (req: Request, res: Response, next: NextFunction) => {
    try {
        if (!req.body) {
            throw new InternalFlowiseError(StatusCodes.PRECONDITION_FAILED, `Error: chatflowsController.saveChatflow - body not provided!`)
        }
        const orgId = req.user?.activeOrganizationId
        if (!orgId) {
            throw new InternalFlowiseError(
                StatusCodes.NOT_FOUND,
                `Error: chatflowsController.saveChatflow - organization ${orgId} not found!`
            )
        }
        const workspaceId = req.user?.activeWorkspaceId
        if (!workspaceId) {
            throw new InternalFlowiseError(
                StatusCodes.NOT_FOUND,
                `Error: chatflowsController.saveChatflow - workspace ${workspaceId} not found!`
            )
        }
        const subscriptionId = req.user?.activeOrganizationSubscriptionId || ''
        const body = req.body

        const existingChatflowCount = await chatflowsService.getAllChatflowsCountByOrganization(body.type, orgId)
        const newChatflowCount = 1
        await checkUsageLimit('flows', subscriptionId, getRunningExpressApp().usageCacheManager, existingChatflowCount + newChatflowCount)

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Decode JWT and confirm activeOrganizationId is present.
  2. Ensure the user has at least one org membership; assign one if missing.
  3. Verify auth middleware that injects the org claim runs on the route.
  4. Re-login / refresh token after org assignment.

Example fix

// before: token without org claim
// after: ensure org membership, re-login
await api.post('/auth/login', creds)
await api.post('/api/v1/chatflows', payload)
Defensive patterns

Strategy: validation

Validate before calling

function hasOrgClaim(user): boolean {
  return Boolean(user && (user as any).activeOrganizationId)
}
if (!hasOrgClaim(currentUser)) {
  // ensure org membership / re-login instead of saving
}

Type guard

function hasOrgContext(u: unknown): u is { activeOrganizationId: string } {
  return typeof u === 'object' && u !== null
    && typeof (u as any).activeOrganizationId === 'string' && (u as any).activeOrganizationId.length > 0
}

Prevention

When it happens

Trigger: Authenticated POST with body present but token lacking activeOrganizationId. Common for fresh accounts without org membership or tokens minted before the multitenant rollout.

Common situations: User has no organization membership; org-resolving auth middleware did not run; legacy token; test stub missing the field.

Related errors


AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12). Data as JSON: /api/errors/9dc2039ab0f9e401. Report an issue: GitHub.