{"record":{"id":"4325cda2e3278093","repo":"passbolt/passbolt_api","slug":"the-identifier-should-be-a-valid-uuid","errorCode":null,"errorMessage":"The identifier should be a valid UUID.","messagePattern":"The identifier should be a valid UUID\\.","errorType":"validation","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltCe/Metadata/src/Model/Validation/MetadataBatchUpdateValidationService.php","lineNumber":62,"sourceCode":"    abstract public function getForm(): MetadataBatchUpgradeForm;\n\n    /**\n     * @param array $requestData Request data.\n     * @return array\n     * @throws \\Cake\\Http\\Exception\\BadRequestException If data is invalid.\n     * @throws \\App\\Error\\Exception\\CustomValidationException If data is invalid.\n     * @throws \\Cake\\Http\\Exception\\NotFoundException If one or more resources are not found.\n     */\n    public function validateMany(array $requestData): array\n    {\n        foreach ($requestData as $values) {\n            if (!is_array($values)) {\n                throw new BadRequestException(__('The entity must be an array.'));\n            }\n\n            $id = $values['id'] ?? null;\n            if (!Validation::uuid($id)) {\n                throw new BadRequestException(__('The identifier should be a valid UUID.'));\n            }\n        }\n\n        $entityIds = Hash::extract($requestData, '{n}.id');\n        $this->entities = $this->queryEntitiesFromIds($entityIds)->all()->toArray();\n        // Re-arrange entities array to set key as identifier and value as entity object to easily find it\n        $this->entities = Hash::combine($this->entities, '{n}.id', '{n}');\n\n        $data = [];\n        $errors = [];\n        foreach ($requestData as $i => $entity) {\n            $entityId = $entity['id'];\n            if (!array_key_exists($entityId, $this->entities)) {\n                throw new NotFoundException(__('Entity {0} not found.', $entityId));\n            }\n\n            /** @var \\Passbolt\\Metadata\\Model\\Entity\\MetadataKey|null $metadataKey */\n            $metadataKey = $this->entities[$entityId]['metadata_key'] ?? null;","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Metadata/src/Model/Validation/MetadataBatchUpdateValidationService.php#L44-L80","documentation":"In MetadataBatchUpdateValidationService::validateMany, after the array check each entry must carry a valid UUID in its `id` field; Validation::uuid() failure throws this BadRequestException. The IDs are then used to load the entities, so invalid identifiers abort the whole batch.","triggerScenarios":"Batch metadata update requests where an entry's `id` is missing, null, empty, an integer, or otherwise not a RFC 4122 UUID; calling validateMany with entities whose identifier key was renamed or not provided.","commonSituations":"Scripts passing resource/folder row numbers instead of UUIDs; payloads using a wrong key (e.g. `resource_id`) so `id` resolves to null; UUIDs truncated or quoted inconsistently by a serializer.","solutions":["Ensure every batch entry has an `id` key holding a valid UUID string (e.g. 8-4-4-4-12 hex).","Run Cake\\Validation\\Validation::uuid($id) on each identifier client-side before sending.","Fix key naming so the entity identifier is under `id`, not `resource_id`/`folder_id`.","Reject/repair malformed entries before the batch call instead of letting the whole batch fail."],"exampleFix":"// before\n{\"id\": \"12345\"}\n\n// after\n{\"id\": \"8e1a4b60-1c2f-4b3a-9c8d-0e5f6a7b8c9d\"}","handlingStrategy":"validation","validationCode":"use Cake\\Validation\\Validation;\nforeach ($batch as $entry) {\n    if (!isset($entry['id']) || !Validation::uuid($entry['id'])) {\n        throw new InvalidArgumentException('Batch entry id must be a valid UUID');\n    }\n}","typeGuard":"function isUuid(mixed $v): bool {\n    return is_string($v) && preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i', $v) === 1;\n}","tryCatchPattern":"try {\n    $data = $service->validateMany($requestData);\n} catch (BadRequestException $e) {\n    // sanitize ids: repair/extract UUIDs then resubmit, or report bad entry\n}","preventionTips":["Always use UUID strings for entity identifiers, never numeric row ids","Name the identifier key `id`, not `resource_id`/`folder_id`","Validate ids with Validation::uuid() or a regex before sending","Watch for truncated/malformed UUIDs produced by string slicing or serializers"],"tags":["passbolt","batch-update","uuid","validation","bad-request"],"backgroundTag":"invalid-identifier-format","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"}