Post payload to custom route

Hello; i end up thinking that i’m a noob at searching on google; but it’s been an hour and noclue about posting a payload to a custom route

Having set this one :

array(
      'pattern' => 'webhooks',
      'action' => function() {
        // trying hard get and parse the submitted data
        return response::json(["updated" =>'ok']);
      },
      'method' => 'POST'
    )

and curl’ing with the following basic command :

curl -d '{"id":"12", "handle":"xx"}' -H "Content-Type: application/json" -X POST http://localhost:3000/webhooks

The payload is just nowhere to be found within the action (I obviously want to parse the submitted payload).
It might be way easier that what i’ve failed to try; it is just that i’ve seen no example in the docs or here
Thanks a lot for pointing that out ;

besties

You are not fetching the data:

[
      'pattern' => 'webhooks',
      'action' => function() {
        $payload = get(); // then do something with the payload
        return response::json(["updated" =>'ok']);
      },
      'method' => 'POST'
]

Knew it would have been easy; just haven’t found a clue. Thx a lot lot

One thing; havent tried yet but feels like it could matter; the route is declared in a plugin, should the get() method be called from some instance or is it available anywhere within an action ?

The get helper is available in plugins.

1 Like

Sorry to bother again, but I don’t find much clue again about what’s happenning and the reasons about it

Here’s what I get then

array(1) {
  ["{"id":"12",_"handle":"xx"}"]=>
  string(0) ""
}

The content dot not get parsed, neither is parsable

Is this normal behaviour ?

I don’t know, it looks strange.

You probably need the raw post data, which it seems is possible to grab like this:

$payload = file_get_contents('php://input');