{"record":{"id":"740182958993c2a8","repo":"mem0ai/mem0","slug":"either-memoryid-or-all-is-required","errorCode":null,"errorMessage":"Either memoryId or --all is required","messagePattern":"Either memoryId or --all is required","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"cli/node/src/backend/platform.ts","lineNumber":338,"sourceCode":"\t\t\tconst params: Record<string, string> = { source: \"CLI\" };\n\t\t\tif (opts.userId) params.user_id = opts.userId;\n\t\t\tif (opts.agentId) params.agent_id = opts.agentId;\n\t\t\tif (opts.appId) params.app_id = opts.appId;\n\t\t\tif (opts.runId) params.run_id = opts.runId;\n\t\t\treturn (await this._request(\"DELETE\", \"/v1/memories/\", {\n\t\t\t\tparams,\n\t\t\t})) as Record<string, unknown>;\n\t\t}\n\t\tif (memoryId) {\n\t\t\tconst params: Record<string, string> = { source: \"CLI\" };\n\t\t\tif (opts.deleteLinked) params.delete_linked = \"true\";\n\t\t\treturn (await this._request(\n\t\t\t\t\"DELETE\",\n\t\t\t\t`/v1/memories/${encodePathSegment(memoryId)}/`,\n\t\t\t\t{ params },\n\t\t\t)) as Record<string, unknown>;\n\t\t}\n\t\tthrow new Error(\"Either memoryId or --all is required\");\n\t}\n\n\tasync deleteEntities(opts: EntityIds): Promise<Record<string, unknown>> {\n\t\t// v2 endpoint: DELETE /v2/entities/{entity_type}/{entity_id}/\n\t\tconst typeMap: [string, string | undefined][] = [\n\t\t\t[\"user\", opts.userId],\n\t\t\t[\"agent\", opts.agentId],\n\t\t\t[\"app\", opts.appId],\n\t\t\t[\"run\", opts.runId],\n\t\t];\n\t\tconst entities = typeMap.filter(([, v]) => v) as [string, string][];\n\t\tif (entities.length === 0) {\n\t\t\tthrow new Error(\"At least one entity ID is required for deleteEntities.\");\n\t\t}\n\t\t// Delete each provided entity via the v2 path-based endpoint. Key each\n\t\t// response by entity type so a multi-entity delete (e.g. --user-id and\n\t\t// --agent-id together) doesn't discard everything but the last result.\n\t\tconst results: Record<string, unknown> = {};","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/cli/node/src/backend/platform.ts#L320-L356","documentation":"The 401 branch of require_admin: the resolved user is None (no JWT, no API key, or admin/disabled auth that returned None) AND auth_type is neither 'admin_api_key' nor 'disabled' — meaning no credential was presented at all and no bootstrap fallback applies. Admin endpoints demand at least one of: an authenticated user, ADMIN_API_KEY, or AUTH_DISABLED.","triggerScenarios":"Calling admin-only endpoints (DELETE /memories, POST /reset, DELETE /api-keys/{id} is require_auth not this) with no Authorization/X-API-Key headers; sending an invalid JWT that verify_auth silently ignores, leaving user=None and auth_type='none'.","commonSituations":"Automation scripts hitting admin endpoints after a server upgrade added auth; expired JWT access token that the bearer branch treats as unauthenticated; reverse proxy stripping headers as in error 681.","solutions":["Authenticate with a Bearer token belonging to an admin-role user (POST /auth/login with the admin registered at /setup).","Or set ADMIN_API_KEY in the server env and send it as X-API-Key.","If the access token expired, refresh it via POST /auth/refresh and retry.","For local dev only, AUTH_DISABLED=true also satisfies this guard when a default user exists."],"exampleFix":"# before\nrequests.delete(f\"{BASE}/memories\", params={\"user_id\": \"alice\"})  # 401\n\n# after\ntok = requests.post(f\"{BASE}/auth/login\", json={\"email\": ADMIN_EMAIL, \"password\": ADMIN_PW}).json()\nrequests.delete(f\"{BASE}/memories\", params={\"user_id\": \"alice\"},\n                headers={\"Authorization\": f\"Bearer {tok['access_token']}\"})","handlingStrategy":"try-catch","validationCode":"def ensure_admin_token(base: str, email: str, password: str) -> str:\n    r = requests.post(f\"{base}/auth/login\", json={\"email\": email, \"password\": password})\n    r.raise_for_status()\n    return r.json()[\"access_token\"]","typeGuard":null,"tryCatchPattern":"if resp.status_code == 401:\n    tok = ensure_admin_token(BASE, ADMIN_EMAIL, ADMIN_PASSWORD)\n    resp = requests.request(method, url, headers={\"Authorization\": f\"Bearer {tok}\"}, ...)\n    resp.raise_for_status()","preventionTips":["Automate token acquisition instead of assuming anonymous access works.","Refresh access tokens proactively before expiry.","Keep ADMIN_API_KEY configured as a break-glass credential for admin endpoints."],"tags":["auth","http-401","admin","rest-server"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}