I am making an attempt to arrange a {custom} endpoint.
I have been following https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/ however I can not get the path to register.
Under is my code.
<?php
add_action('rest_api_init', 'register_plugin_routes');
perform register_plugin_routes()
{
register_rest_route( 'mchs/v1', '/take a look at',
[
'methods' => 'GET',
'callback' => 'mchs_test'
]
);
register_rest_route( 'mchs/v1', '/search/?P<search_email>S+',
[
'methods' => ['GET','POST'],
'callback' => 'mchs_search_by_email',
'args' => [
'search_email' => [
'validate_callback' => function( $param, $request, $key ) {
return is_email( $param );
}
]
]
]
);
}
perform mchs_search_by_email( WP_REST_Request $request )
{
$param = $request->get_param('search_email');
return search_hubspot( $param );
}
perform mchs_test ( WP_REST_REQUEST $request )
{
return "This can be a take a look at.";
}
The route I am making an attempt to entry is http://web site.take a look at/wp-json/mchs/v1/search/john@instance.com
Utilizing http://web site.take a look at/wp-json/mchs/v1/search?search_email=john@instance.com does not work both.
There isn’t any indication of why something is failing, all I get in response is
{
"code": "rest_no_route",
"message": "No route was discovered matching the URL and request methodology.",
"information": {
"standing": 404
}
}
I do know the script is loading as a result of I can name http://web site.take a look at/wp-json/mchs/v1/take a look at and get a profitable response.
What’s flawed with my name to register_rest_route() ? Is it the best way I am making an attempt to entry it?