{"record":{"id":"728e837a9a4fe935","repo":"passbolt/passbolt_api","slug":"the-metadata-private-key-data-is-not-valid","errorCode":null,"errorMessage":"The metadata private key data is not valid.","messagePattern":"The metadata private key data is not valid\\.","errorType":"validation","errorClass":"CustomValidationException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltCe/Metadata/src/Service/MetadataPrivateKeysCreateService.php","lineNumber":232,"sourceCode":"                    'user_id' => $data['user_id'],\n                    'data' => $data['data'],\n                    'created_by' => $uac->getId(),\n                    'modified_by' => $uac->getId(),\n                ],\n                [\n                    'accessibleFields' => [\n                        'metadata_key_id' => true,\n                        'user_id' => true,\n                        'data' => true,\n                        'created_by' => true,\n                        'modified_by' => true,\n                    ],\n                ]\n            );\n\n            if ($entity->getErrors()) {\n                $errors = [$i => $entity->getErrors()];\n                throw new CustomValidationException(__('The metadata private key data is not valid.'), $errors);\n            }\n\n            $entities[] = $entity;\n        }\n\n        return $entities;\n    }\n\n    /**\n     * Throw exception for the entity by preserving the array index of entity.\n     *\n     * @param \\Cake\\ORM\\Exception\\PersistenceFailedException $exception Exception object.\n     * @param array $entities Entities were being stored.\n     * @return void\n     * @throws \\App\\Error\\Exception\\CustomValidationException\n     */\n    protected function handleSaveManyValidationException(PersistenceFailedException $exception, array $entities): void\n    {","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Metadata/src/Service/MetadataPrivateKeysCreateService.php#L214-L250","documentation":"In buildEntities, each MetadataPrivateKey entity is patched and validated individually; if $entity->getErrors() is non-empty, a CustomValidationException is thrown with this message and an errors array keyed by entity index. Unlike handleValidationErrors (used by create), this is the many-items path with per-index error details.","triggerScenarios":"createMany receives a list where at least one item fails entity validation — e.g. item 2 has a non-UUID user_id or malformed 'data' payload.","commonSituations":"Mixed-quality batch payloads where most items are fine but one was built with an outdated client; copy-paste errors in bulk share scripts.","solutions":["Read the errors map in the exception response; the outer index identifies the failing item in the submitted array","Fix the flagged fields in that item and resend the corrected batch","Validate each item client-side (UUID user_id, string 'data') before submitting the batch"],"exampleFix":"// before\n$items[2] = ['user_id' => 'not-a-uuid', 'data' => '...'];\n// after\n$items[2] = ['user_id' => '3a2b1c...uuid', 'data' => '...'];","handlingStrategy":"validation","validationCode":"const valid = items.every(it => typeof it.data === 'string' && (it.user_id === undefined || UUID_RE.test(it.user_id)));","typeGuard":"const isValidItem = (it) => typeof it?.data === 'string' && (it.user_id === undefined || isUuid(it.user_id));","tryCatchPattern":"catch (e) { if (e.body?.errors) { for (const [idx, errs] of Object.entries(e.body.errors)) fixItem(items[idx], errs); return retry(); } throw e; }","preventionTips":["Validate every item in a batch before submission","Read the per-index errors map the exception returns","Keep bulk scripts using the same client version as interactive flows"],"tags":["validation","http-422","batch","metadata"],"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"}