passbolt/passbolt_api · error · BadRequestException

Information about the key is required.

Error message

Information about the key is required.

What it means

Thrown by SsoKeysCreateController::create() when the request body is empty, not an array, or contains zero items. Creating an SSO server key requires key metadata (e.g. certificate data) in the POST payload; an empty body cannot be processed.

Solutions

  1. Send a non-empty JSON body with the key data, e.g. {"certificate": "..."}
  2. Set Content-Type: application/json on the request
  3. Inspect the serialized request body to ensure it isn't stripped by a proxy or client library
  4. Confirm the correct HTTP method (POST) and endpoint are used

Example fix

// before
await api.post('/sso/keys');
// after
await api.post('/sso/keys', {certificate: serverKeyCertificatePem}, {headers:{'Content-Type':'application/json'}});
Defensive patterns

Strategy: validation

Validate before calling

const payload = {certificate: certPem};
if (!payload || typeof payload !== 'object' || Object.keys(payload).length === 0) {
  throw new Error('SSO key payload must be a non-empty object');
}

Type guard

function isNonEmptyObject(v: unknown): v is Record<string, unknown> {
  return typeof v === 'object' && v !== null && Object.keys(v).length > 0;
}

Try / catch

try {
  await createSsoKey(payload);
} catch (e) {
  if (e.response?.status === 400 && e.response?.data?.message?.includes('Information about the key is required')) {
    // fix serialization / Content-Type and retry
  }
}

Prevention

When it happens

Trigger: POST /sso/keys with no body, an empty JSON object {}, or a payload that CakePHP fails to parse into an array.

Common situations: Client sent JSON without Content-Type: application/json so getData() returns empty; forgot to serialize the key payload; framework stripped the body due to middleware or size limits.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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

Appendix: source

Thrown at plugins/PassboltEe/Sso/src/Controller/Keys/SsoKeysCreateController.php:36

use App\Controller\AppController;
use Cake\Http\Exception\BadRequestException;
use Passbolt\Sso\Service\SsoKeys\SsoKeysCreateService;

class SsoKeysCreateController extends AppController
{
    /**
     * Create SSO Passphrase Key
     *
     * @throws \App\Error\Exception\ValidationException if data do not validate
     * @throws \Cake\Http\Exception\InternalErrorException if saving data is not possible
     * @return void
     */
    public function create(): void
    {
        $data = $this->request->getData();
        if (!isset($data) || !is_array($data) || !count($data)) {
            throw new BadRequestException(__('Information about the key is required.'));
        }

        $uac = $this->User->getAccessControl();
        $key = (new SsoKeysCreateService())->create($uac, $data);

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

View on GitHub (pinned to 31c1bbc10f)