{"record":{"id":"e0d659683d620df0","repo":"passbolt/passbolt_api","slug":"could-not-validate-the-metadata-key-data-e0d659","errorCode":null,"errorMessage":"Could not validate the metadata key data.","messagePattern":"Could not validate the metadata key data\\.","errorType":"validation","errorClass":"FormValidationException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltCe/Metadata/src/Controller/MetadataKeyUpdateController.php","lineNumber":51,"sourceCode":"     * @param string $id key uuid\n     * @return void\n     * @throws \\Cake\\Http\\Exception\\NotFoundException if the key does not exist or is already expired\n     * @throws \\Cake\\Http\\Exception\\BadRequestException if the key format is invalid or some conditions are not met\n     * @throws \\Cake\\Http\\Exception\\InternalErrorException if there was an issue during the save/delete\n     */\n    public function update(string $id): void\n    {\n        $this->assertJson();\n        $this->User->assertIsAdmin();\n        $this->assertNotEmptyArrayData();\n\n        if (!Validation::uuid($id)) {\n            throw new BadRequestException(__('The metadata key ID should be a valid UUID.'));\n        }\n\n        $form = new MetadataKeyUpdateForm();\n        if (!$form->execute($this->getRequest()->getData())) {\n            throw new FormValidationException(__('Could not validate the metadata key data.'), $form);\n        }\n\n        $dto = MetadataKeyUpdateDto::fromArray($form->getData());\n        (new MetadataKeyUpdateService())->update($this->User->getAccessControl(), $id, $dto);\n        $this->success(__('The operation was successful.'));\n    }\n}\n","sourceCodeStart":33,"sourceCodeEnd":59,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Metadata/src/Controller/MetadataKeyUpdateController.php#L33-L59","documentation":"Payload guard in the metadata key update action: after the UUID check, the request body data failed validation (e.g. missing or malformed fields such as expired date), and a 400 summarizing the invalid metadata key data is thrown before the service layer runs.","triggerScenarios":"Update call with missing required fields, invalid metadata key type, malformed armored key, or extra invalid fields in the JSON body.","commonSituations":"Patching only some fields when the form requires them; sending v4 field names; forgetting the JSON body entirely; content-type mismatch causing empty data.","solutions":["Read the form errors attached to the exception and correct the offending fields.","Send a complete valid body matching MetadataKeyUpdateForm rules (e.g. metadata_key_type, armored_key, key_info).","Ensure Content-Type: application/json and a non-empty payload.","Confirm the key is not expired/f revoked per update rules."],"exampleFix":"// before\nput(`/metadata/keys/${id}`, {metadata_key_type: 'shared'});\n// after\nput(`/metadata/keys/${id}`, {metadata_key_type: 'shared_key', armored_key: armored, key_info: info});","handlingStrategy":"validation","validationCode":"const required = ['metadata_key_type', 'armored_key', 'key_info'];\nif (required.some(k => !(k in body))) throw new Error('missing fields: ' + required.filter(k => !(k in body)));","typeGuard":"const isValidUpdate = (b) => typeof b === 'object' && b !== null && ['shared_key','user_key'].includes(b.metadata_key_type);","tryCatchPattern":"try { await api.put(`/metadata/keys/${id}`, body); } catch (e) { if (e.response?.status === 400 && e.response?.data?.body?.metadata_key?.errors) applyFieldErrors(e.response.data.body.metadata_key.errors); else throw e; }","preventionTips":["Send complete form payloads, not partial patches.","Mirror MetadataKeyUpdateForm rules in client validation.","Check debug logs / error body for per-field messages."],"tags":["validation","cakephp","form-validation","api"],"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"}