passbolt/passbolt_api · error · FormValidationException

Could not validate the metadata key data.

Error message

Could not validate the metadata key data.

What it means

MetadataKeysController.create validates the POST payload with MetadataKeyCreateForm; when the form fails execution (missing/invalid fields such as armored public key, key info, or expired metadata), it throws this BadRequestException carrying the form's nested validation errors.

Solutions

  1. Inspect the nested form errors in the exception to see which fields failed and fix the payload.
  2. Ensure the request body is valid JSON with required keys (e.g. armored_key, key_info) and Content-Type: application/json.
  3. Verify the user is authenticated as admin before calling the endpoint.
  4. Confirm the key data matches v5 metadata key requirements (valid OpenPGP armored key).

Example fix

// before
await fetch('/metadata/keys', {method:'POST'});
// after
await fetch('/metadata/keys', {method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({armored_key: pubArmored, key_info: {fingerprint, subkeys}})});
Defensive patterns

Strategy: validation

Validate before calling

const body = {armored_key, key_info};
if (!body.armored_key || !body.key_info?.fingerprint) throw new Error('metadata key payload incomplete');

Type guard

const isMetadataKeyPayload = (b) => typeof b === 'object' && b !== null && typeof b.armored_key === 'string' && b.armored_key.startsWith('-----BEGIN PGP PUBLIC KEY BLOCK-----');

Try / catch

try { await api.post('/metadata/keys', body); } catch (e) { if (e.response?.status === 400 && e.response?.data?.body?.metadata_key?.errors) { handleFormErrors(e.response.data.body.metadata_key.errors); } else throw e; }

Prevention

When it happens

Trigger: POST /metadata/keys with an absent or malformed body, missing 'armored_key'/'key_info' fields, non-admin caller body issues, or a payload that fails MetadataKeyCreateForm rules.

Common situations: API clients sending v4-style key payloads to the v5 metadata keys endpoint; missing Content-Type: application/json so getData() returns empty; automated scripts posting incomplete payloads.

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/bfb25273bd81648d. Report an issue: GitHub.

Appendix: source

Thrown at plugins/PassboltCe/Metadata/src/Controller/MetadataKeyCreateController.php:40

use Passbolt\Metadata\Model\Dto\MetadataKeyCreateDto;
use Passbolt\Metadata\Service\MetadataKeyCreateService;

class MetadataKeyCreateController extends AppController
{
    /**
     * Metadata key save action.
     *
     * @return void
     */
    public function create()
    {
        $this->assertJson();
        $this->User->assertIsAdmin();
        $this->assertNotEmptyArrayData();

        $form = new MetadataKeyCreateForm();
        if (!$form->execute($this->getRequest()->getData())) {
            throw new FormValidationException(__('Could not validate the metadata key data.'), $form);
        }

        $dto = MetadataKeyCreateDto::fromArray($form->getData());
        $uac = $this->User->getAccessControl();
        $metadataKey = (new MetadataKeyCreateService())->create($uac, $dto);

        $this->success(__('The operation was successful.'), $metadataKey);
    }
}

View on GitHub (pinned to 31c1bbc10f)