passbolt/passbolt_api · error · Cake\Http\Exception\BadRequestException
This is not a valid Ajax/Json request.
Error message
This is not a valid Ajax/Json request.
What it means
A BadRequestException thrown by NotificationOrgSettingsPostController::_validateRequestData when the request is not recognized as a JSON/Ajax request. Passbolt controllers of this style require the Accept header to indicate JSON so the request body can be parsed as JSON data.
Solutions
- Add header 'Accept: application/json' to the request.
- Send the payload with 'Content-Type: application/json' and a JSON body.
- If using the passbolt JS SDK or an XHR client, keep the default XHR headers (X-Requested-With) intact.
- Do not submit the endpoint via a plain HTML form post.
Example fix
// before
curl -X POST -H 'X-Http-Token: <token>' -d 'settings=1' /email-notification-settings/org-settings
// after
curl -X POST -H 'X-Http-Token: <token>' -H 'Content-Type: application/json' -H 'Accept: application/json' -d '{"send_admin_user_setup_complete":true}' /email-notification-settings/org-settings Defensive patterns
Strategy: validation
Validate before calling
if (stripos($acceptHeader, 'application/json') === false) {
throw new BadRequestException('Request must accept application/json');
} Try / catch
try {
$response = $client->postEmailNotificationOrgSettings($data);
} catch (BadRequestException $e) {
if (str_contains($e->getMessage(), 'Ajax/Json')) {
// add Accept: application/json / Content-Type: application/json and retry once
}
} Prevention
- Always send 'Accept: application/json' and 'Content-Type: application/json' headers to passbolt JSON endpoints.
- Use an HTTP client wrapper that sets JSON headers by default.
- Avoid plain HTML form posts against JSON-only controllers.
- In tests, use $this->postJson() / assert json type to mirror production calls.
When it happens
Trigger: POST to /email-notification-settings/org-settings with role check passing but without 'application/json' in the Accept header (and not an XHR request), so $this->request->is('json') returns false.
Common situations: Calling the endpoint with curl or Postman with default Accept header (text/html, */*); form posts from plain HTML without X-Requested-With; integration scripts forgetting the Accept: application/json header.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Ajax/Json request not supported.
- Ajax/Json request not supported.
- Please use .json extension in URL or accept…
- This is not a valid Ajax/Json request.
- This is not a valid Ajax/Json request.
AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17).
Data as JSON: /api/errors/11f3f01410dfea6a.
Report an issue: GitHub.
Appendix: source
Thrown at plugins/PassboltCe/EmailNotificationSettings/src/Controller/NotificationOrgSettings/NotificationOrgSettingsPostController.php:71
$msg = __('The notification settings for the organization were updated.');
$this->success($msg, $this->_formatForOutput($flatten));
}
/**
* Validate the request body
*
* @return array if the request body is valid
* @throws \Cake\Http\Exception\ForbiddenException If the user making request is not admin
* @throws \Cake\Http\Exception\BadRequestException If the request is not a Ajax/Json type
*/
private function _validateRequestData(): array
{
if ($this->User->role() !== Role::ADMIN) {
throw new ForbiddenException(__('You are not allowed to access this location.'));
}
if (!$this->request->is('json')) {
throw new BadRequestException(__('This is not a valid Ajax/Json request.'));
}
$data = $this->request->getData();
foreach ($data as $key => $value) {
$data[$key] = QueryStringComponent::normalizeBoolean($value);
}
$form = new EmailNotificationSettingsForm();
if (!$form->validate($data)) {
$errors = $form->getErrors();
throw new CustomValidationException(__('The supplied email notification settings are not valid'), $errors);
}
$data = EmailNotificationSettingsForm::formatFormDataToOrgSettings($data);
View on GitHub (pinned to 31c1bbc10f)