OS X Execute a script while printing Is it possible to make OS X execute a script when document is printed ?

My printer is connected to a power switch which is controlled with a REST API and the idea is to switch the printer on only when it is needed (basically while printing).

Any command (bash, AppleScript) can be used if it can make a call to a rest API (http://10.10.0.1/switchon).
Common Unix Printing System

macOS uses the Common Unix Printing System (CUPS) for printing. This open source system does allow for calling scripts and more.

Knowing this, the search for cups pre-print script returns some good starting points.

Virtual Printer to Real Printer Workflow

The StackOver questions Programming a Filter/Backend to 'Print to PDF' with CUPS from any Mac OS X application and Run a script on files sent to a CUPS print queue? offer an example where a virtual printer is used to pre-process a print job before passing it onto a real printer.

In your situation, the pre-processing could be to power on your printer via the REST API.

Alternatively…

See also Run command before and after printing with CUPS?