passbolt/passbolt_api · error · BadRequestException

Subscription key data is required.

Error message

Subscription key data is required.

What it means

EditionSubscriptionsCreateController::create reads the subscription key from the request 'data' field. If the value is missing, not a string, or an empty/whitespace-only string, it throws BadRequestException. The endpoint requires the raw subscription key payload in the request body.

Solutions

  1. Send the subscription key as a non-empty string in the request 'data' field
  2. Check the request Content-Type and encoding so 'data' is parsed correctly
  3. Trim and verify the key content before calling the API

Example fix

// before
await fetch('/edition/subscriptions', {method: 'POST', body: JSON.stringify({})});
// after
await fetch('/edition/subscriptions', {method: 'POST', body: JSON.stringify({data: subscriptionKeyString})});
Defensive patterns

Strategy: validation

Validate before calling

const data = payload.data;
if (typeof data !== 'string' || data.trim() === '') {
  throw new Error('Subscription key data is required.');
}

Type guard

function hasKeyData(v: unknown): v is string { return typeof v === 'string' && v.trim().length > 0; }

Try / catch

try {
  await api.post('/edition/subscriptions', {data: key});
} catch (e) {
  if (e.status === 400) { /* fix request payload: data must be non-empty string */ }
}

Prevention

When it happens

Trigger: POSTing to the edition subscription endpoint with no 'data' field, with a non-string value (array/null), or with an empty/whitespace string.

Common situations: Client sends JSON without the data key; form/multipart encoding where the key lands in the wrong field; copying a subscription key that was actually empty; API client sending nested payload in wrong location.

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

Appendix: source

Thrown at plugins/PassboltCe/Edition/src/Controller/EditionSubscriptionsCreateController.php:45

use Passbolt\Subscription\Error\Exception\Subscriptions\SubscriptionSignatureException;

/**
 * The in-product upgrade entry point.
 */
class EditionSubscriptionsCreateController extends AppController
{
    use LocatorAwareTrait;

    /**
     * @return void
     */
    public function create(): void
    {
        $this->User->assertIsAdmin();

        $keyString = $this->getRequest()->getData('data');
        if (!is_string($keyString) || trim($keyString) === '') {
            throw new BadRequestException(__('Subscription key data is required.'));
        }

        $this->assertNotAlreadyPro();

        try {
            $keyDto = (new EditionUpgradeService())->upgrade($keyString, $this->User->getAccessControl());
        } catch (SubscriptionSignatureException $e) {
            throw new BadRequestException($e->getMessage());
        } catch (SubscriptionException $e) {
            throw new PaymentRequiredException($e->getMessage(), $e->getErrors());
        }

        $this->success(__('The subscription was created.'), $keyDto->toArray());
    }

    /**
     * Rejects with HTTP 409 if the instance is already on PRO or already has a
     * persisted subscription row.

View on GitHub (pinned to 31c1bbc10f)