API to download all kubeconfig

I am trying to download kubeconfig for all the downstream clusters as we do from the UI.

 curl -s -k -X 'POST' \
     -H "Authorization: Bearer $RANCHER_TOKEN" \
     $RANCHER_URL/v3/clusters/$CLUSTER_ID?action=generateKubeconfig | jq -r ".config" > $CLUSTER_NAME.kubeconfig

This is looping over all the clusters id’s and getting the config, what’s the best way to get all clusters config as one single config file?

I just wanted to mention the way I ended up achieving this. After generating kubeconfigs for all the clusters, merge them down to a single kubeconfig using the below command,

export KUBECONFIG=$(ls  *.kubeconfig|tr '\n' ':')
echo "Merging all kubeconfig to a single file"
kubectl config view --merge --flatten >all_merged.config