我试图在我的存储中创建一个路由,以接收来自API的通知,但每次我测试我创建的路由时,都会收到以下错误消息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\',
) );
});
当我通过邮递员打电话时,总是会出现以下错误GET: https://planetmusicexpress.com/wp-json/cbt-api/v1/notifications/?merchant_id=765&resource=\\/orders\\/MBR010131&topic=orders
我的这段代码在我创建的插件中,我确信我的插件正在工作,因为我在与这段代码相同的文件中调用了其他插件。有人知道我做错了什么吗?我知道我的路线有效,因为它出现在这里https://planetmusicexpress.com/index.php/wp-json
我不知道的是在get上装入她的调用,或者装入正则表达式,使其看起来与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\',
) );
});
我在响应中进行了建议的更改,但当我这样做时,我的路径get和post都返回null:https://planetmusicexpress.com/wp-json/cbt-api/v1/notifications/?merchant_id=765&resource=MBR010131&topic=orders