I had developed a controller to retrieve data from an API via a webhook. This is the type of data I received with https://webhook.site for testing :
{
"owner": {
"id": "100000",
"userName": "lorem"
},
"notes": "",
"created": {
"dateTime": "2021-12-14T18:54:36",
"timeZone": "Europe/Paris"
},
Here is a preview of the controller :
class WebhookLoremController extends ControllerBase {
public function LoremListener(Request $request) {
$data_webhook = $request->getContent();
// data is invalid
dump($request);
// data is invalid
dump($data_webhook);
// obviously doesn't work as $data_webhook is invalid
$decode = Json::decode($data_webhook);
}
}
Everything was working fine but now the data received is invalid. We can see the @ character for example, or problems with comma, colon, or } :
{
"owner":"@""id":"100000",
"userName":"lorem",
"notes":"",
"created":"@""dateTime":"2021-12-14T18:54:36",
"timeZone":"Europe/Paris",
I immediately thought of a problem with the API but I have no problem if I test with https://webhook.site. I take it that the problem is on my side. If I dump $request
the problem is already there.
It worked before and I did not change the code. The only thing I'm thinking about is that I updated to Drupal 9 but I'm not sure if that has anything to do with it.
Do I have to do something with drupal to retrieve this kind of data?
EDIT
Here is the dump()
of $request
:
"POST /webhook/listener-api-lorem-10000 HTTP/1.1 Authorization":"Content-Length":"3607 Content-Type":"application/json Host":"lorem.fr User-Agent":"Jakarta Commons-HttpClient/3.1 X-Agendize-Objectevent":"deleted X-Autonomous-System":"16276 X-Country-Code":"FR X-Forwarded-Port":"443 X-Forwarded-Proto":"https X-Php-Ob-Level":"1 X-Ssl":"yes"{
"owner":"@""id":"10000",
"userName":"lorem",
"notes":"",
"created":"@""dateTime":"2021-12-14T20:04:36",
"timeZone":"Europe/Paris"