Thursday, August 25, 2022
HomeWordPress Developmentphp - get_body_params() is all the time empty in POST request

php – get_body_params() is all the time empty in POST request


I’m registering a customized route like this :

add_action('rest_api_init', operate () {
  register_rest_route( 'professeurEQ', 'statistics', array(
          'strategies'  => 'POST',
          'callback' => 'test_proeq_post',
      ));
});

The callback is written like this :

operate test_proeq_post($request) {
  $jsonParams = $request->get_body_params();
  return var_dump($jsonParams);
}

I’m sending the POST request utilizing Postman and the next physique :

{
    "userID" = 3
}

No matter I’m doing, the $jsonParams is all the time empty. The identical factor occurs with strategies like get_json_params or get_params or get_param.

get_body() works, however I want to obtain an array and use the get_body_params() technique.

If I do

var_dump($request)

Then I see the total request, and I observed all of the parameters are protected. I believe it have to be the reason for the issue, however methods to clear up it ?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments