Upgrading SLEEKY plugin for YOURLS to use new Unsplash API for background

I have a simple YOURLS link shortening website running the Sleeky theme plugin. The background set in config.php as

define('backgroundImage', 'https://source.unsplash.com/category/landscape');

It seems the old API does not work any more so the background function is broken.

I tried running the following js to try and make it work but I am obviously doing something fundamentaly wrong:

<script type="text/javascript">
fetch("https://api.unsplash.com/search/photos?query=background&client_id=xxxxxxxxxxxxxxxxxxxxxx")
    .then(
        function(response){
            
            
            if(response.status !== 200){
                console.log("There was a problem. Status code: " + response.status);
                return;
            }

            response.json().then(
                
                   document.body.style.backgroundImage = 'url(' + data["results"][0]["urls"]["regular"]+')';
                
            )
        }
    )
    .catch(
        function(err){
            console.log(err+'404');
        }
        )
</script>

Would you be able to steer me in the right direction please?