Policy evaluation based on external rest api call

I want to evaluate a policy based on external api call response.i explored javascript based policy
as per below link -
https://www.keycloak.org/docs/latest/authorization_services/index.html#_policy_js
tried below example but not working
fetch(‘https://ghibliapi.herokuapp.com/films’)
.then(function() {
$evaluation.grant();
})
.catch(function() {
$evaluation.deny();
});