Why wp_ajax hooks doesn’t work?

You can add a WordPress Rest API custom endpoint
Docs