When I start an ngrok client with ./ngrok tcp 22 it runs in the foreground and I can see the randoming generated forwarding URL, such as tcp://0.tcp.ngrok.io:
./ngrok tcp 22
tcp://0.tcp.ngrok.io:
If you want to get the first tunnel then jq will be your friend:
jq
curl -s localhost:4040/api/tunnels | jq -r .tunnels[0].public_url
When running more than one instance of ngrok then use the tunnel name /api/tunnels/:name.
/api/tunnels/:name