• Resolved joelwolfgang

    (@joelwolfgang)


    I’m using Beta 10, PHP 7 on localhost with MAMP

    My permalinks are set to postname.

    The standard endpoints users, posts, etc are working correctly.

    I’ve added these two functions in order to get a list of the post ids through the endpoint ‘/post-ids’

    I get the response returned:

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

    When I look at my namespaces I see my custom name space. I feel I’m close, but missing something small.

    public function register_routes() {
    				$version = '1';
    				$namespace = 'wpapi-testing/v' . $version;
    				$base = 'post-ids';
    				register_rest_route( $namespace, '/' . $base, array(
    							'methods'         => 'GET',
    							'callback'        => 'my_awesome_func'
    						)
    					);
    			}
    
    	function my_awesome_func() {
    	        $all_post_ids = get_posts( array(
    	            'numberposts' => -1,
    	            'post_type'   => 'post',
    	            'fields'      => 'ids',
    	        ));
    		    return $all_post_ids;
    	}

    https://wordpress.org/plugins/json-rest-api/

Viewing 1 replies (of 1 total)
  • Thread Starter joelwolfgang

    (@joelwolfgang)

    Ok, I figured it out.

    I was using the wrong route. I was using /wp-json/wp/v2/post-ids/ when I should have been using /wp-json/wpapi-testing/v1/post-ids/.

    This was not entirely clear in the documentation. I had to research it. This explanation could easily be added to the documentation of the register_rest_route() function.

Viewing 1 replies (of 1 total)
  • The topic ‘Custom Endpoint 404’ is closed to new replies.