Converting JWT call to Oauth = 401

I am using Powershell to download recorded meetings, and as per JWT October’s deadline, I am attempting to modify the code accordingly. JWT still working, while when passing Oauth token as bearer, system will return 401 (unauthorised).
I’m wondering if the token format is wrong, or if the token is invalid.

Initialisation (working perfectly)


    $uri = "https://zoom.us/oauth/token?grant_type=account_credentials&account_id={0}" -f $AccountID

    #Encoding of the client data
    $IDSecret = $ClientID + ":" + $ClientSecret 
    $EncodedIDSecret = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($IDSecret))

    $headers = @{
        "Authorization" = "Basic $EncodedIDSecret"  
    }
            
    # Maybe add some error handling
    try {
        $response = Invoke-WebRequest -uri $uri -headers $headers -Method Post
    } catch {
        $_
    }

    Write-Verbose 'Acquired token.'
    
    $token = ($response.content | ConvertFrom-Json).access_token

    $token = ConvertTo-SecureString -String $token -AsPlainText -Force

Download after getting user recording list
JWT version (working)

 # invoke JWT token creation
        $JWT = Generate-JWT -Algorithm 'HS256' -type 'JWT' -Issuer $ZoomApiKey  -SecretKey $ZoomApiSecret -ValidforSeconds 7200 # was 3200
        # Add token to download URL
        $jwtURL = $item.URL + "?access_token=" +  $JWT
        $outfile = "$($downloadsFolder)\$fileName"
        $StartDate=(GET-DATE)
        Write-Host "Downloading to $outfile [Zoom Time: $($item.StartDate)] - "+$(Format-Bytes $item.Size)+"..."

        # Download recording
        try {
            $ProgressPreference = 'SilentlyContinue'
           $r = Invoke-WebRequest -Uri $jwtURL -OutFile $outfile
            $a = [int]$r.StatusCode
        }
        catch {
            $a = [int]$_.Exception.Response.StatusCode
        }

Oauth download (not working)


        $bearer_token = (ConvertFrom-SecureString $Global:PSZoomToken)
        $headers = @{Authorization = "Bearer $bearer_token"}
        $outfile = "$($downloadsFolder)\$fileName"
        $StartDate=(GET-DATE)
        Write-Host "Downloading to $outfile [Zoom Time: $($item.StartDate)] - "+$(Format-Bytes $item.Size)+"..."

        # Download recording
        try {
            $ProgressPreference = 'SilentlyContinue'
            $r = Invoke-RestMethod  -Uri $item.URL -Method 'Post' -OutFile $outfile -Headers $headers -UseBasicParsing 
            $a = [int]$r.StatusCode
        }
        catch {
            $a = [int]$_.Exception.Response.StatusCode
        }