Getting posted JSON in Body of POST web hook

I am using CakePHP 5.0.5 to write an App that connect to Strava and get running activities for users.

Strava require a webhook so that it can push update event of user activity to my app.
Strava documentation does not tell all the parameters and data of the web hook POST.

I am writing a bit of code to get all parsedBody and put in app_logs table for analysing the posted data and it structure.

However, I can’t get all data in log, due to some of the are array inside JSON !?!?

This code get the POST body:

if ($this->request->is('post')) {
            $object_type = $this->request->getQuery('object_type');
            $requestQuery = $this->request->getQueryParams();
            $requestData = $this->request->getParsedBody();
            
            //the input () function does not exist
            //$requestJSON = $this->request->input('json_decode');



            if (!is_null($object_type)){
            
            }

            $this->addLog($requestQuery);
            $this->addLog($requestData);
            //$this->addLog($requestJSON);

            $this->set('result', 'OK');
            $this->viewBuilder()->setOption('serialize', ['result']);
            
            return;
        }

This Code log the POST body into string field in app_logs table

public function addLog(mixed $content){
        $logTable = $this->fetchTable('AppLogs');

        $log = $logTable->newEntity(['name' => implode(', ', $content)]);
        $logTable->save($log);
    }

Anh this is what I get in database:

update, 1711896540, 11075006063, activity, 70175148, 257235, Array

I have read CakePHP 5 documentation, but this bit does not exist

you are in CakePHP, not Laravel.


If the data is actually present inside the POST request then

$requestData = $this->request->getParsedBody();

should contain it.


don’t know why you are doing such a complicated logging mechansim but just calling

\Cake\Log\Log::info(print_r($requestData, true));

should put the data inside your logs/debug.log file

Yes Sir, I am reading CakePHP document , and that line of sample code that I said does not exist is actually in CakePHP documentation.

And no Sir, I did not aware of that logging mechanism. Thank you for pointing out the Debug Log for me, Sir. That’s a nice feature.