Custom Endpoint Coming In as Array not JSON
-
I registered a custom endpoint (in a class) using:
add_action( 'rest_api_init', array( $this, 'rest_api_init' ) ); function rest_api_init(){ register_rest_route( 'partners/v1', '/create/partner', array( 'methods' => 'POST', 'callback' => array( $this, 'rest_api_create_partner' ), ) ); }
The POST is JSON from an ember app which validates as JSON, and has a parameter of
data
.Inside
rest_api_create_partner()
, I have tried to accessdata
using both:$data = $request->get_param( 'data' ); $body = $request->get_body_params();
I’m expecting
data
to give meid:1,name:"Company Name"
but what I’m actually getting when printing to the WP DEBUG LOG is:[data] => Array ( [0] => Array ( [id] => 1 ) [1] => Array ( [name] => Company Name ) ) )
Is my code suspect, or the data coming over? Am I missing a step in creating this endpoint that would cause the JSON received to be decoded into an array like this?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Custom Endpoint Coming In as Array not JSON’ is closed to new replies.