{"record":{"id":"67f073900ed4415c","repo":"passbolt/passbolt_api","slug":"could-not-validate-user-data-userseditcontroller","errorCode":null,"errorMessage":"Could not validate user data.","messagePattern":"Could not validate user data\\.","errorType":"validation","errorClass":"App\\Error\\Exception\\FormValidationException","httpStatus":422,"severity":"error","filePath":"src/Controller/Users/UsersEditController.php","lineNumber":69,"sourceCode":"     * @param string $id user uuid\n     * @param \\League\\Flysystem\\FilesystemAdapter $filesystemAdapter file system adapter to write the avatar in cache if saved\n     * @param \\App\\Service\\Resources\\ResourcesExpireResourcesServiceInterface $resourcesExpireResourcesService Service to expire resources that were consumed by users who lost access to them.\n     * @return void\n     */\n    public function editPost(\n        string $id,\n        FilesystemAdapter $filesystemAdapter,\n        ResourcesExpireResourcesServiceInterface $resourcesExpireResourcesService\n    ) {\n        $this->assertJson();\n        $data = $this->request->getData();\n        $data['id'] = $id;\n\n        $this->assertCanEdit($data);\n\n        $form = new UsersEditForm();\n        if (!$form->execute($data)) {\n            throw new FormValidationException(__('Could not validate user data.'), $form);\n        }\n\n        $this->assertRequestData($data);\n\n        // Try to find the user and validate changes it\n        /** @var \\App\\Model\\Table\\UsersTable $usersTable */\n        $usersTable = $this->fetchTable('Users');\n        $this->Users = $usersTable;\n        try {\n            /** @var \\App\\Model\\Entity\\User $user */\n            $user = $this->Users->findView($id, $this->User->role())->first();\n        } catch (Exception $exception) {\n            throw new BadRequestException(__('The user does not exist or has been deleted.'));\n        }\n        if (empty($user)) {\n            throw new BadRequestException(__('The user does not exist or has been deleted.'));\n        }\n        $wasDisabledNull = is_null($user->disabled);","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/src/Controller/Users/UsersEditController.php#L51-L87","documentation":"editPost runs the submitted data through UsersEditForm; if form->execute() fails (field-level validation: email format, profile fields, role assignment rules, gpg key data, etc.), it throws FormValidationException 'Could not validate user data.' with the form's errors attached to the response.","triggerScenarios":"PUT /users/<id>.json with invalid payload: malformed email, unknown role id, invalid profile first/last name, extra forbidden fields, or wrong types.","commonSituations":"Client sending role changes the form disallows; omitting required profile fields; sending quoted strings where ids expected; API version drift between client and server.","solutions":["Read the 400 response body: FormValidationException exposes per-field errors under errors","Fix the flagged fields (valid email, role id, profile names) and resubmit","Send only the fields UsersEditForm accepts; check the form schema for your server version","Test the payload against the dry-run/edit form rules before calling in production"],"exampleFix":"// before\nPUT /users/<id>.json {\"role_id\": \"admin\"} // string, not UUID\n// after\nPUT /users/<id>.json {\"role_id\": \"0d3f5d10-9b11-5b3d-a1d2-5f0e8d3f0b1e\", \"profile\": {\"first_name\": \"Ada\", \"last_name\": \"Lovelace\"}}","handlingStrategy":"validation","validationCode":"const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\nconst errors = {};\nif (payload.email && !/^[^@\\s]+@[^@\\s]+$/.test(payload.email)) errors.email = 'invalid';\nif (payload.role_id && !UUID_RE.test(payload.role_id)) errors.role_id = 'must be a UUID';\nif (payload.profile?.first_name && !payload.profile.first_name.trim()) errors.first_name = 'required';","typeGuard":null,"tryCatchPattern":"try { await api.editUser(id, payload); } catch (e) { if (e.status === 400 && e.body?.errors) { showFieldErrors(e.body.errors); return; } throw e; }","preventionTips":["Map the API 400 errors field-by-field into your form UI","Send only fields the UsersEditForm accepts; consult the server's OpenAPI/schema docs","Validate email and role_id format client-side before submitting","Pin client version to server API version"],"tags":["validation","form","user-management"],"backgroundTag":"schema-validation-failed","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}