Get swarm join tokens via API

I’m trying to automate the bootstrapping of swarm clusters via the API but I’m struggling on how to get the tokens. I can see all the methods for joining/leaving but nothing that will return the current tokens.

My reference is https://docs.docker.com/engine/reference/api/docker_remote_api_v1.24/

At present, the only way I can see to get the tokens is to run the docker CLI and “scrape” the output but that is a bit too ugly for production.