Test WordPress api with postman
I have some API endpoints.
For example:
add_action('rest_api_init', function () {
register_rest_route(MY_APP_NAMESPACE, '/init', array(
'methods' = 'GET',
'callback' = function (WP_REST_Request $request) {
return get_current_user_id();
}
));
}
I am trying to test this endpoint with Postman.
I have generated 'X-WP-Nonce' with my localized script. And I am taking the nonce code from the browser console, and passing it through postman Headers.
But I am getting
{
"code": "rest_cookie_invalid_nonce",
"message": "Cookie nonce is invalid",
"data": {
"status": 403
}
}
But when I am trying with Ajax, in the same WordPress environment its works fine.
I think this is happening because the nonce is generated in a different session, so with another client, it can't respond.
My question is how can I test my API's with postman?