Script to setup mail forwarding rule

Hi

Is it possible to run a script to setup a rule to fwd emails to an external email address, e.g. via a REST api?

Instead of logging to the users account and setting up the rule.

Thanks