T
T
Turtle_Onni2021-10-06 09:19:43
RESTful API
Turtle_Onni, 2021-10-06 09:19:43

How to make POST REST API without authorization in Wordpress?

Hello!

How can I make a POST REST API without authorization in Wordpress?
For now, wp's answer gives the answer:

{
    "code": "restx_logged_out",
    "message": "Sorry, you must be logged in to make a request.",
    "data": {
        "status": 401
    }
}


My request:
add_action('rest_api_init', function () {
    register_rest_route('custom/v1', '/user', array(
        'methods' => 'POST',
        'permission_callback' => '__return_true',
        'callback' => function (WP_REST_Request $Request) {
            return $Request;
        },
    ));
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question