passbolt/passbolt_api · error · CustomValidationException

Could not validate the metadata key data for the entity…

Error message

Could not validate the metadata key data for the entity with ID: {0}.

What it means

For each valid batch entry, validateMany executes the plugin's update form ($form->execute($entity)). When the form fails validation, it collects $form->getErrors() and throws CustomValidationException with this message, attaching the per-entity error details. It signals the metadata key data (metadata_key_id / metadata_key_type combination) did not pass form rules.

Solutions

  1. Inspect the CustomValidationException's errors payload ($form->getErrors()) to see the exact failing field and rule, then fix that field.
  2. Verify the metadata_key_id references an existing, non-deleted metadata key (GET /metadata/keys.json).
  3. Ensure metadata_key_type matches the key ('shared_key' or 'user_key') and is consistent with metadata_key_id.
  4. Enable debug logging to see per-entity validation errors during the batch, and resubmit corrected entries.

Example fix

// before
{"id": "<uuid>", "metadata": "<encrypted>", "metadata_key_id": "nonexistent-key-uuid", "metadata_key_type": "shared_key"}

// after (use a valid key id from GET /metadata/keys.json)
{"id": "<uuid>", "metadata": "<encrypted>", "metadata_key_id": "<valid-active-key-uuid>", "metadata_key_type": "shared_key"}
Defensive patterns

Strategy: try-catch

Validate before calling

$key = $metadataKeysTable->find()->where(['id' => $metadataKeyId, 'deleted' => false])->first();
if (!$key) {
    throw new InvalidArgumentException('metadata_key_id must reference an existing, non-deleted key');
}
if (!in_array($metadataKeyType, [MetadataKey::TYPE_SHARED_KEY, MetadataKey::TYPE_USER_KEY], true)) {
    throw new InvalidArgumentException('Invalid metadata_key_type');
}

Type guard

function isValidMetadataKeyRef(?string $keyId, ?string $keyType): bool {
    return $keyId !== null && $keyType !== null
        && in_array($keyType, ['shared_key', 'user_key'], true);
}

Try / catch

try {
    $data = $service->validateMany($requestData);
} catch (CustomValidationException $e) {
    $errors = $e->getErrors(); // per-entity form errors; fix fields then resubmit
}

Prevention

When it happens

Trigger: Batch metadata updates where an entity's metadata_key_id/metadata_key_type pair is invalid — e.g. referencing a nonexistent or deleted metadata key, mismatched key type, missing fields required by the form, or a personal-key rule violation caught by setMetadataKeyIdIfNotDefinedAndEntityIsPersonal.

Common situations: Migrating resources to a metadata key that was revoked/deleted; sending metadata_key_type 'shared_key' with a user key ID or vice versa; automation omitting metadata_key_id expecting the server to infer it; form schema changes after a passbolt upgrade.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17). Data as JSON: /api/errors/90b2f38753bbb2a2. Report an issue: GitHub.

Appendix: source

Thrown at plugins/PassboltCe/Metadata/src/Model/Validation/MetadataBatchUpdateValidationService.php:90

        $errors = [];
        foreach ($requestData as $i => $entity) {
            $entityId = $entity['id'];
            if (!array_key_exists($entityId, $this->entities)) {
                throw new NotFoundException(__('Entity {0} not found.', $entityId));
            }

            /** @var \Passbolt\Metadata\Model\Entity\MetadataKey|null $metadataKey */
            $metadataKey = $this->entities[$entityId]['metadata_key'] ?? null;
            if (!is_null($metadataKey)) {
                $metadataKey = $metadataKey->toArray();
            }
            $entity['metadata_key'] = $metadataKey;
            $entity = $this->setMetadataKeyIdIfNotDefinedAndEntityIsPersonal($entity);

            $form = $this->getForm();
            if (!$form->execute($entity)) {
                $errors[$i] = $form->getErrors();
                throw new CustomValidationException(__('Could not validate the metadata key data for the entity with ID: {0}.', $entityId), $errors); // phpcs:ignore;
            }
            $data[$i] = $form->getData();
        }

        return $data;
    }

    /**
     * Returns fetched entities from the DB.
     *
     * @return array
     */
    public function getEntities(): array
    {
        return $this->entities;
    }

    /**

View on GitHub (pinned to 31c1bbc10f)