It's possible to record an action for that, so it's probably also possible to create and run that action on the fly. If you search this forum, I'm sure you'll find it.
That's a fair answer. Playing an action is often a workaround to a missing C++ API, though it can come with constraints. For something like this though, it probably does the job. @Rick E Johnson is right as well about examples on the forum: I know I've read & answered many questions on PlayAction, just do a search for that.
One issue when using actions this way is that you won't get back much meaningful information, just an error code. If the action creates or changes art, it will be selected -- the same is true for the swatches in your case. You will have to figure out for yourself if the action did anything useful.