• I’ve added several custom endpoints for handling a couple of custom post types and also users, and no matter what I try, I’m getting an empty request object sent to my callback functions.

    This is one of the register_rest_route calls:

    register_rest_route( 'customapi/v1', '/account', array(
    			array(
    				'methods' => WP_REST_Server::EDITABLE,
    				'callback' => array($this, 'update_user'),
    				'permission_callback' => function () {
    					return current_user_can( 'edit_posts' );
    				},
    				'args' => array()
    			),
    			array(
    				'methods' => WP_REST_Server::CREATABLE,
    				'callback' => array($this, 'create_user'),
    				'permission_callback' => function () {
    					return current_user_can( 'edit_posts' );
    				},
    				'args' => array()
    			)
    		));

    And for testing purposes I’ve removed all the extra functionality for the update_user function, so it simply returns the contents of the $request.

    public function update_user( WP_REST_Request $request) {
    		
    		$params = $request->get_params();
    		return new WP_REST_Response( array('params' => $params), 200 );
    		
    	}

    And it doesn’t matter what I POST or PUT in the body of my wp_remote_request call, the request object that is passed to my callback is always empty, regardless of whether the body of the request is an array or a JSON encoded string.

    Losing patience quickly!!

    Anyone have any ideas?

The topic ‘Always empty body for custom endpoints’ is closed to new replies.