I was having some issues to connect to my vCloud Director tenant via the API

My connection attempt ended up in this error message: Couldn’t connect to cloud server with the provided session id.
I used this script https://github.com/jondwaite/vcdapitoken/blob/main/vcd-token.ps1 to make the API connection.
My powerCLI version was “VMware.PowerCLI 13.1.0 build 21624340”. It turns out there is an issue in the Connect-CIServer command in this version. Someone in the community (Jasper Boschman) told me to use the PowerCLI version 13.0.0.20829139.
When you need to install an older PowerCLI version it is recommended to uninstall all other VMware modules first. If you only uninstall VMware.PowerCLI it will keep the VMware.VimAutomation.* modules untouched.
Get-Module VMware.* -ListAvailable | Uninstall-Module -Force
Then you can install the version you need
Install-Module -Name VMware.PowerCLI -RequiredVersion 13.0.0.20829139
The downside is that PowerCLI 13.0.0.20829139 will install VMware.VimAutomation.Cloud 13.1.0.21611174. So you need to install the older Cloud module and remove the new one.
install-Module VMware.VimAutomation.Cloud -RequiredVersion 13.0.0.20809912
get-Module VMware.VimAutomation.Cloud -ListAvailable | where {$_.version -match '13.1'} | Uninstall-Module
When you follow these steps you are able to connect to de vCloud Dorectory API again.
Instead of downgrading to the old vCD version you should just change the value that you’re passing to the Connect-CIServer command.
You should change it like this:
Connect-CIServer -Server $vcdhost -SessionId “Bearer $($access_token)”