How to use wp_ajax_set_post_thumbnail?
Assuming you’re looking at calling this via an AJAX style call from your browser, I’d suggest you look at the new WordPress REST API. Here’s the docs for the endpoint for updating posts. This will allow you to do exactly the same thing with the featured_media parameter, and much more, and is likely much better … Read more