0

I have a controller action that will be used for webhook handler.

When I did the form post to that URL with header content-type:

application/x-www-form-urlencoded

My load is:

MyVariableOne=ValueOne&MyVariableTwo=ValueTwo

On the action's execute function, I had $data as

$data = $this->getRequest()->getPostValue();

When I do var_dump, I got:

array(2) { ["MyVariableOne"]=> string(8) "ValueOne" ["MyVariableTwo"]=> string(8) "ValueTwo" }

But when I change the content-type to application/json and set payload to:

{"MyVariableOne":"ValueOne","MyVariableOne":"ValueTwo"}

the var_dump now become:

array(0) { }

Am I missing some steps to make my webhook hanlder support

Thank you,

1 Answer 1

0

Turned out JSON Payload doesn't like to be mapped by $this->getRequest()->getPostValue(); Instead I have to fall back to primitive PHP command.

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

$data = json::decode($request_body,true);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.