{"record":{"id":"116bc320e0cbb052","repo":"passbolt/passbolt_api","slug":"entity-0-not-found","errorCode":null,"errorMessage":"Entity {0} not found.","messagePattern":"Entity (.+?) not found\\.","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"plugins/PassboltCe/Metadata/src/Model/Validation/MetadataBatchUpdateValidationService.php","lineNumber":76,"sourceCode":"            }\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;\n            if (!is_null($metadataKey)) {\n                $metadataKey = $metadataKey->toArray();\n            }\n            $entity['metadata_key'] = $metadataKey;\n            $entity = $this->setMetadataKeyIdIfNotDefinedAndEntityIsPersonal($entity);\n\n            $form = $this->getForm();\n            if (!$form->execute($entity)) {\n                $errors[$i] = $form->getErrors();\n                throw new CustomValidationException(__('Could not validate the metadata key data for the entity with ID: {0}.', $entityId), $errors); // phpcs:ignore;\n            }\n            $data[$i] = $form->getData();\n        }\n","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Metadata/src/Model/Validation/MetadataBatchUpdateValidationService.php#L58-L94","documentation":"validateMany loads all entities referenced by the batch IDs from the database and re-indexes them by ID. When an entry's ID is not found among the loaded entities, it throws NotFoundException('Entity {0} not found.'). This means the referenced resource or folder does not exist (or is not visible to the requesting user).","triggerScenarios":"Batch metadata update requests containing an `id` that matches no accessible resource/folder row — deleted entities, wrong database, IDs from another instance, or soft-deleted/permission-filtered records.","commonSituations":"Migrating batches exported from one passbolt instance into another; concurrent deletion of a resource between listing and updating; stale client caches holding IDs of removed folders/resources; missing permission on the entity so the query excludes it.","solutions":["Verify the entity exists with the exact UUID (GET /resources/<id>.json or /folders/<id>.json) before including it in the batch.","Remove stale/deleted IDs from the batch payload and resubmit.","Check the authenticated user's permissions (ARE) on the entities — the lookup is permission-filtered.","Confirm you are querying the intended instance/database (avoid mixing exported IDs across environments)."],"exampleFix":"// before (id from another instance, not found)\n[{\"id\": \"11111111-1111-1111-1111-111111111111\", ...}]\n\n// after (fetch fresh IDs first)\n$resources = json_decode(file_get_contents($url . '/resources.json?contain[id]=1'), true);\n$ids = array_column($resources, 'id');","handlingStrategy":"validation","validationCode":"$existing = $resourcesTable->find('list', ['keyField' => 'id'])\n    ->where(['id IN' => array_column($batch, 'id')])->toArray();\n$missing = array_diff(array_column($batch, 'id'), array_keys($existing));\nif ($missing) {\n    throw new InvalidArgumentException('Unknown ids: ' . implode(', ', $missing));\n}","typeGuard":"function allEntitiesExist(array $ids, callable $lookup): bool {\n    return empty(array_diff($ids, $lookup($ids)));\n}","tryCatchPattern":"try {\n    $data = $service->validateMany($requestData);\n} catch (NotFoundException $e) {\n    // parse the missing id from the message, drop it from the batch, and resubmit\n}","preventionTips":["Fetch fresh entity ids before each batch (avoid stale caches)","Re-check existence after concurrent operations that may delete entities","Ensure the requesting user has permission (ARE) on every entity in the batch","Never reuse ids exported from a different passbolt instance or environment"],"tags":["passbolt","batch-update","not-found","entity","rest-api"],"backgroundTag":"entity-not-found","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"}