If I were you, I’d put the logic into a route that you can then call from your script: Routing | Kirby CMS
Otherwise, you would have to bootstrap kirby into your external script, like in this example (How to migrate users | Kirby CMS), which makes sense for such on-off scripts, but for your use case, better go with option 1.
Routes are very powerful. You can do anything with them if you need logic to be available from a URL.
Note that you can’t use the $kirby variable outside of templates and snippets, but have to use kirby() instead or if you need it more often, store the object in a variable:
Hm, is that your complete code? I would expect that your route returns something to the fetch request.
Apart from that, your PHP code is missing some check that the page exists before trying to update it, and ideally, you would wrap this update method in a try/catch block, so that you can return something useful to your JS script in case updating fails.