• I have written a custom REST endpoint for WP REST API to change the user avatar. It is working in my local WordPress installation, but when I try to access the endpoint in my shared host WordPress I get a error saying.

    {
        "code": "rest_no_route",
        "message": "No route was found matching the URL and request method",
        "data": {
            "status": 404
        }
    }

    Even the htaccess files in local installation and the server look identical. The plugin file look like this:

    /*Function to get directory URL*/
        function getContentUrl()
        {   
            return WP_CONTENT_URL."/uploads/avatars/";
        }
    
        /*Function to get directory local path*/
        function getContentDirectory(){
            return WP_CONTENT_DIR."/uploads/avatars/";
        }
    
        /*Initializing Rest API Endpoint*/
        add_action('rest_api_init',function(){
            /*--Avatar Change Custom API--*/
            register_rest_route('custom/v1', '/avatarchange/',array(
                'methods' => 'POST',
                'callback' => 'changeAvatar',
                'args' => array(
                    'userid' => array(),
                    'fname' => array(),
                    'lname' => array(),
                    'image' => array(),
                ),
                'permission_callback' => function(){
                    //return current_user_can( 'read' );
                return true;
                } 
            ));
            /*--Get Userid from Email Custom API--*/
            register_rest_route('custom/v1', '/getuid/',array(
                'methods' => 'POST',
                'callback' => 'getUidFromEmail',
                'args' => array(
                    'email' => array(),
                ),
                'permission_callback' => function(){
                    return current_user_can( 'read' );
                } 
            ));
        });
  • The topic ‘Error – rest_no_route in custom WP REST API endpoint’ is closed to new replies.