• Resolved Optimizr

    (@william-greatman)


    Hi,

    Thanks for the great plugin. I am trying to create mobile apps for my website and I need to show the slideshow on my app. In previous app, I am using /wp-json/wp/v2/mtslides?_embed and it is running fine.

    But on new site, the route seems to be changed and I am getting following error

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

    According to other support threads, I think the routes are listed here /wp-json/metaslider/v1/. Correct me if I am wrong.

    What I want for now is just to display single slideshow on my mobile apps. But every sub routes I entered required authentication because I got following message when I entered (for example) /wp-json/metaslider/v1/slideshow/all

    {"code":"rest_forbidden","message":"Sorry, you are not allowed to do that.","data":{"status":401}}

    I just want to show a slideshow that is publicly available on the web. Why do I need authorization to do so? Or am I in wrong direction or doing something wrong? Please guide me or at least let me have the detailed documentation if you have one.

    Thanks in advance.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Hi,

    May I know what versions of WordPress and MetaSlider you have on your old site compared to what version you are currently using now.

    Thread Starter Optimizr

    (@william-greatman)

    Thank you for your reply. Surprisingly, both sites have the same latest versions.

    WP ? Version 6.0
    Meta Slider ? Version 3.27.6

    Hi,

    I have informed by our team that there were no changes made in regards to our API.

    It’s most-likely that there are other factors that might’ve cause the issue since you mentioned that the same version of WordPress and MetaSlider has been running fine on your other server.

    Thread Starter Optimizr

    (@william-greatman)

    Even the server is the same for both sites. Just this endpoint
    /wp-json/wp/v2/mtslides?_embed
    isn’t working on new site. Could you please confirm if it is the right endpoint? If this should work, I would try with default theme and/or deactivating other plugins.

    There are only two registered post types in MetaSlider (ml-slider and ml-slide)

    So, you’d have to use the following routes.
    /wp-json/wp/v2/ml-slide
    /wp-json/wp/v2/ml-slider

    But, before you can access the following routes, you’d have to modify the show_in_rest value to true. You can do this by adding the following code below to your functions.php.

    add_filter( 'register_post_type_args', 'customize_metaslider_post_type', 10, 2 );
    function customize_metaslider_post_type( $args, $post_type ) {
        
        if ( in_array($post_type, ['ml-slide', 'ml-slider'] ) ) {
            $args['show_in_rest'] = true;
        }
    
        return $args;
    }
    
    Thread Starter Optimizr

    (@william-greatman)

    Thank you! This pointed me in the right direction. In my old working site, I have this in my functions.php

    /**
     * Add REST API support to an already registered post type.
     */
    add_filter('register_post_type_args', 'metaslider_args', 10, 2);
    
    function metaslider_args($args, $post_type)
    {
    
    	if ('ml-slide' === $post_type) {
    		$args['show_in_rest'] = true;
    
    		// Optionally customize the rest_base or rest_controller_class
    		$args['rest_base']             = 'mtslides';
    		$args['rest_controller_class'] = 'WP_REST_Posts_Controller';
    	}
    
    	return $args;
    }

    And now, I can use the same endpoint as my old working site.

    That’s good news! Glad we are able to help.

    I will mark this as resolved. Feel free to open a new issue in case you need anything else.

    • This reply was modified 2 years, 4 months ago by Arreane.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Documentation for REST API?’ is closed to new replies.