• Resolved tavakal4devs

    (@tavakal4devs)


    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)
  • Plugin Support abhiladdha07

    (@abhiladdha07)

    Hi @tavakal4devs,

    Thanks for reaching out.

    As we understand it, you are trying to authenticate the custom-built REST endpoint in WordPress using our plugin.

    So, we would like to inform you that with the free plan of the plugin only supports the capabilities for authenticating WordPress native REST endpoints and the features for authenticating custom build or 3rd-party plugin endpoints along with more security are available in the pro plans only.

    With the free plan, you can either only block them from access or open them publicly using their own default authentication if any.

    You can check more details about this Custom API Authentication feature from this [LINK]

    Also, it will be great if you can reach out to us at [email protected] so our technical team can provide more details on this and help you out.

    Thanks,
    Team miniOrange

Viewing 1 replies (of 1 total)
  • The topic ‘plugin not working with custom endpoint’ is closed to new replies.