How to create the notebook code with parameters and execute it with a command?

Perhaps see this existing discussion:

Basically: there are a number of existing commands which will give you access to some higher-level APIs.