I’m trying to create a route in my store, to receive notifications from an API, but every time I test the route I created, I get this error message No route was found matching the URL and request method
function notifications_cbt_func($request) {
return $request;
}
add_action('rest_api_init', function () {
register_rest_route( 'cbt-api/v1', '/notifications/', array(
'methods' => 'GET',
'callback' => 'notifications_cbt_func',
) );
});
when I make my call via postman always gives this error
GET: https://planetmusicexpress.com/wp-json/cbt-api/v1/notifications/?merchant_id=765&resource=\/orders\/MBR010131&topic=orders
this code of mine is inside a plugin that I created, I’m sure my plugin is working, because I have others called within the same file as this code that are working. Can anyone have any idea what I’m doing wrong?
I know my route works because it appears here https://planetmusicexpress.com/index.php/wp-json
what I don’t know is to mount her call on get, or mount the regular expression so that it looks the same as it is on my get
EDIT
function notifications_cbt_func($request) {
$merchant_id = $request->get_param( 'merchant_id' );
$resource = $request->get_param( 'resource' );
// Get all the parameters:
$params = $request->get_params();
return json_encode($$params);
}
add_action('rest_api_init', function () {
register_rest_route( 'cbt-api/v1', '/notifications/', array(
'methods' => 'GET',
'callback' => 'notifications_cbt_func',
) );
});
add_action('rest_api_init', function () {
register_rest_route( 'cbt-api/v1', '/notifications/', array(
'methods' => 'POST',
'callback' => 'notifications_cbt_func',
) );
});
I made the changes suggested in the responses, but my route both get and post are returning null when I do this:
https://planetmusicexpress.com/wp-json/cbt-api/v1/notifications/?merchant_id=765&resource=MBR010131&topic=orders