Failed to call service script/caddy2_restart. Undefined

If I access the developer tools/services page via this url “https://hass.sacl.duckdns.org/developer-tools/service
and call the “script.caddy2_restart” script I get the error message
“Failed to call service script/caddy2_restart. Undefined”. Nothing is logged.

However, If I access it via the local url:
http://192.168.0.100:8123/developer-tools/service” the script runs properly.

When used locally, the duckdns.org urls are rerouted via my caddy2 reverse proxy. The local url is obviously not.

When called in an automation, the script will fail.

Can anyone shed light on what is happening and/or how to fix it? Thanks.