diff --git a/application/Espo/Core/Api/RequestWrapper.php b/application/Espo/Core/Api/RequestWrapper.php index 2997c3bc38..9952bccbe7 100644 --- a/application/Espo/Core/Api/RequestWrapper.php +++ b/application/Espo/Core/Api/RequestWrapper.php @@ -202,14 +202,20 @@ class RequestWrapper implements ApiRequest $contents = $this->getBodyContents(); if ($this->getContentType() === 'application/json' && $contents) { - $this->parsedBody = Json::decode($contents); + $parsedBody = Json::decode($contents); - if (is_array($this->parsedBody)) { - $this->parsedBody = (object) [ - 'list' => $this->parsedBody, + if (is_array($parsedBody)) { + $parsedBody = (object) [ + 'list' => $parsedBody, ]; } + if (!$parsedBody instanceof stdClass) { + throw new Error("Body is not a JSON object."); + } + + $this->parsedBody = $parsedBody; + return; }