# Getting posted JSON in Body of POST web hook

**URL:** <https://discourse.cakephp.org/t/getting-posted-json-in-body-of-post-web-hook/11966>\
**Category:** Uncategorized\
**Created:** [March 31, 2024, 3:13pm UTC](https://discourse.cakephp.org/t/getting-posted-json-in-body-of-post-web-hook/11966 "2024-03-31T15:13:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![general2000vn](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@general2000vn](https://discourse.cakephp.org/u/general2000vn)\
**Post date:** [March 31, 2024, 3:13pm UTC](https://discourse.cakephp.org/t/getting-posted-json-in-body-of-post-web-hook/11966/1 "2024-03-31T15:13:01Z")

</div>

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:

```auto
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

```auto
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:

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

```

I have read CakePHP 5 documentation, but [this bit does](https://book.cakephp.org/5/en/controllers/request-response.html#Cake%5CHttp%5CServerRequest::input) not exist

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [March 31, 2024, 5:09pm UTC](https://discourse.cakephp.org/t/getting-posted-json-in-body-of-post-web-hook/11966/2 "2024-03-31T17:09:40Z")

</div>

> [@general2000vn](#):
>
> `//the input () function does not exist`

you are in CakePHP, not Laravel.

* * *

If the data is actually present inside the POST request then

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

```

should contain it.

* * *

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

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

```

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

---

<div class="post-metadata">

**Author:** ![general2000vn](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@general2000vn](https://discourse.cakephp.org/u/general2000vn)\
**Post date:** [April 1, 2024, 6:41am UTC](https://discourse.cakephp.org/t/getting-posted-json-in-body-of-post-web-hook/11966/3 "2024-04-01T06:41:06Z")

</div>

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.
