{"record":{"id":"32bf9b5277c8487b","repo":"passbolt/passbolt_api","slug":"could-not-validate-the-data","errorCode":null,"errorMessage":"Could not validate the data.","messagePattern":"Could not validate the data\\.","errorType":"validation","errorClass":"FormValidationException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltCe/Metadata/src/Service/MetadataSessionKeyUpdateService.php","lineNumber":60,"sourceCode":"     * @param \\App\\Utility\\UserAccessControl $uac UAC.\n     * @param string $id The metadata session key identifier.\n     * @param array $data non-empty array of user provided data\n     * @throws \\Cake\\Http\\Exception\\BadRequestException\n     * @throws \\Cake\\Http\\Exception\\NotFoundException\n     * @throws \\Cake\\Http\\Exception\\ConflictException\n     * @throws \\App\\Error\\Exception\\CustomValidationException\n     * @return \\Passbolt\\Metadata\\Model\\Entity\\MetadataSessionKey\n     */\n    public function update(UserAccessControl $uac, string $id, array $data): MetadataSessionKey\n    {\n        if (!Validation::uuid($id)) {\n            throw new BadRequestException(__('The metadata session key identifier should be a UUID.'));\n        }\n\n        // 400 invalid user provided data, we expect [modified:<datetime>, data:<string>]\n        $form = new MetadataSessionKeyUpdateForm();\n        if (!$form->execute($data)) {\n            throw new FormValidationException(__('Could not validate the data.'), $form);\n        }\n        $data = $form->getData();\n\n        /** @var \\Passbolt\\Metadata\\Model\\Table\\MetadataSessionKeysTable $metadataSessionKeysTable */\n        $metadataSessionKeysTable = $this->fetchTable('Passbolt/Metadata.MetadataSessionKeys');\n\n        try {\n            /** @var \\Passbolt\\Metadata\\Model\\Entity\\MetadataSessionKey $metadataSessionKey */\n            $metadataSessionKey = $metadataSessionKeysTable\n                ->find()\n                ->where(['id' => $id, 'user_id' => $uac->getId()])\n                ->firstOrFail();\n        } catch (RecordNotFoundException $e) {\n            // 404 session key entry does not exist or not for current user_id\n            throw new NotFoundException(__('The metadata session key does not exist or does not belong to this user.'));\n        }\n\n        // 400 no changes to be made","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Metadata/src/Service/MetadataSessionKeyUpdateService.php#L42-L78","documentation":"update() expects payload data shaped [modified:<datetime>, data:<string>] validated by MetadataSessionKeyUpdateForm. If the form fails to execute, a FormValidationException with message 'Could not validate the data.' is thrown (400).","triggerScenarios":"Missing 'modified' or 'data' fields, 'modified' not a valid datetime, 'data' not a string / failing OpenPGP-related validation, or extra malformed payload.","commonSituations":"Client sends only {'data': ...} without modified, datetime format mismatch (timezone/locale), sending base64 or JSON where the form expects a string, API version drift in payload shape.","solutions":["Send both fields: modified as ISO-8601 datetime and data as string","Read the form's errors from the exception/response to see the exact failing field","Match the payload schema used by the official passbolt clients"],"exampleFix":"// before\n$service->update($uac, $id, ['data' => $armored]);\n// after\n$service->update($uac, $id, ['data' => $armored, 'modified' => $key->modified->format('Y-m-d\\TH:i:sP')]);","handlingStrategy":"validation","validationCode":"$errors = []; if (!isset($data['data']) || !is_string($data['data'])) { $errors[] = 'data must be a string'; } if (!isset($data['modified']) || strtotime($data['modified']) === false) { $errors[] = 'modified must be a datetime'; }","typeGuard":"function isValidUpdatePayload(array $d): bool { return isset($d['data'], $d['modified']) && is_string($d['data']) && strtotime($d['modified']) !== false; }","tryCatchPattern":"try { $service->update($uac, $id, $data); } catch (FormValidationException $e) { $errors = $e->getForm()->getErrors(); }","preventionTips":["Always send both 'modified' (ISO-8601 datetime) and 'data' (string)","Mirror the MetadataSessionKeyUpdateForm schema in the client","Validate payload against the schema before sending"],"tags":["form-validation","bad-request","payload-schema","metadata-session-key"],"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"}