plugin not working with custom endpoint
-
Hi, please take a look to my code
class RestApi { public function __construct() { add_action('rest_api_init',function (){ register_rest_route('v1', '/test/', array( 'methods' => 'GET', 'callback' => [$this,'test'], 'permission_callback' => '__return_true' )); }); } public function test(): int { return get_current_user_id(); } } new RestApi();
when i hit this endpoint , the server return this error message
{ "status": "error", "error": "Restricted", "error_description": "Sorry, you are not allowed to access REST API." }
postman code
curl -X GET \ https://localhost:8003/wp-json/v1/test \ -H 'authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOjEsIm5hbWUiOiJveGVtIiwiaWF0IjoxNjU1MjIyMDUxLCJleHAiOjE4MTI5MDIwNTF9.E29s_lE0APNh7t3IopPc6byVSLphDP-RQPj_hhQ34VE' \ -H 'cache-control: no-cache' \ -H 'content-type: application/json' \ -H 'postman-token: d24ce0d7-0074-1abb-a082-07e07f2ae95c'
PS: it’s working fine with native wordpress endpoints
PS 2: the checkbox is on for (Protected REST API Settings)why am getting this error?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘plugin not working with custom endpoint’ is closed to new replies.