passbolt/passbolt_api · error · CustomValidationException

400

400

Error message

Could not validate request data.

What it means

validateRequestData() aggregates per-item validation errors for the tags payload and, if any remain, throws CustomValidationException('Could not validate request data.') with the error details and HTTP 400. The message is generic; the exception's errors property carries the field-specific failures.

Solutions

  1. Inspect the errors property of the 400 response to see which items/fields failed
  2. Send the documented payload shape: {Tags: [{id: uuid, slug: 'tag-name'}, ...]}
  3. Fix client serialization (stringify arrays, correct field names) and retest with a minimal valid payload

Example fix

// before
await api.post('/resources-tags/id', {Tags: 'alpha, beta'});
// after
await api.post('/resources-tags/id', {
  Tags: [{id: existingTagId, slug: 'alpha'}, {slug: 'beta'}]
});
Defensive patterns

Strategy: validation

Validate before calling

const valid = Array.isArray(tags) && tags.every(t => t && typeof t.slug === 'string' && (t.id === undefined || isUuid(t.id)));
if (!valid) throw new Error('Tags payload must be an array of {id?, slug} objects');

Type guard

const isValidTagsPayload = (d) => Array.isArray(d?.Tags) && d.Tags.every(t => typeof t?.slug === 'string');

Try / catch

try { await addResourceTags(id, payload); } catch (e) { if (e.status === 400 && e.body?.errors) { console.error(e.body.errors); } else throw e; }

Prevention

When it happens

Trigger: POST to resources-tags with a payload whose 'Tags' array items are not valid tag objects (missing/invalid id or slug, wrong types, non-array Tags field), producing non-empty $errors after cleanup.

Common situations: Client sending [{name: ...}] instead of {id, slug} shaped tags; duplicate tags; sending tags as a comma string rather than an array; API version drift changing expected field names.

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

Appendix: source

Thrown at plugins/PassboltEe/Tags/src/Controller/Tags/ResourcesTagsAddController.php:148

                    $form = new MetadataResourcesTagsAddForm();
                }

                if (!$form->execute($tag)) {
                    $errors[$i] = array_merge($errors[$i], $form->getErrors());
                }

                $data[$i] = $this->populatedMetadataUserKeyId($uac->getId(), $form->getData());
            } else {
                $this->assertV4TagCreationEnabled();
            }

            if (empty($errors[$i])) {
                unset($errors[$i]);
            }
        }

        if (!empty($errors)) {
            throw new CustomValidationException(
                __('Could not validate request data.'),
                $errors,
                null,
                400
            );
        }

        return $data;
    }
}

View on GitHub (pinned to 31c1bbc10f)