Share via

Accessing VAAC outside of Power BI

Merlin 5 Reputation points
2023-07-18T13:40:03.5833333+00:00

I'm attempting to access VAAC Data using Postman/PowerShell, but I'm facing some challenges. In the article "Accessing VAAC outside of Power BI," they provide an example of using a username and password, but it didn't work for me, (I used a Work account) --> the Error stated that I need to provid the necessary username parameter (I did that).

Then, I came across this article on StackOverflow LINK, which I'm uncertain if it is still true.

Next, I attempted to access it using the clientId and secret, as they are specifically designed for this purpose. Unfortunately, that approach also didn't yield any results. (I tested all of this in Postman and PowerShell)

Also, is there a list of the scopes that work for this? Because the example uses a string, and PowerShell wants a string with "/.default".

Ah, and the permissions I tried: "Teams Communications Administrator" and "Global Reader" (for user and app).

(I'm also interested to know if the data is the same as from the Graph API from communications/records/sessions?$expand=segments because in the report, there are missed calls displayed, and MS didn't support missed calls in the Graph API w(゚Д゚)w)

I'm open to any advice or suggestions. Here's an example of the PowerShell script I tried:



$body = @{
      grant_type='client_credentials'
      client_id=$appId
      client_secret=$secret
      scope='https://graph.microsoft.com/.default'
      }

$res = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token" -ContentType "application/x-www-form-urlencoded" -Body $body -Method Post
$accessToken = $res.access_token
#Write-Host $accessToken 


$apiUrl = "https://api.interfaces.records.teams.microsoft.com/Teams.VoiceAnalytics/getanalytics"



$response = Invoke-WebRequest -Uri "https://api.interfaces.records.teams.microsoft.com/Teams.VoiceAnalytics/getanalytics" -Method Get -Headers (@{Authorization="Bearer $accessToken"})

Write-Host $response
#this returns a (401) Unauthorized. 

Microsoft Teams | Development
Microsoft Teams | Development

Building, integrating, or customizing apps and workflows within Microsoft Teams using developer tools and APIs

Microsoft Security | Microsoft Graph

4 answers

Sort by: Most helpful
  1. Brian Wiggins 10 Reputation points
    2025-01-27T13:27:15.2466667+00:00

    My script connects fine and retrieves data, but I'm really struggling with the JSON to create the query I want. I've left in the example query, but I'm actually I'm trying to retrieve the agent timeline data to list agents and the number of calls they have taken each day. I think I've cracked the hard bit can anyone assist with the query?

    # Define the API endpoint and authentication details
    $URL = "https://api.interfaces.records.teams.microsoft.com/Teams.VoiceAnalytics/getanalytics?query="
    $TennantId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" # Azure Tenant ID
    $ClientID = "a672d62c-fc7b-4e81-a576-e60dc46e951d"   # Azure Application (Client) ID
    
    # Define the date range for the query
    $FromDate = (Get-Date).AddDays(-7).ToString("yyyy-MM-dd") # Start date (7 days ago)
    $ToDate = (Get-Date).ToString("yyyy-MM-dd")              # End date (today)
    
    # Requires the MSAL.PS module for authentication
    #Requires -Module MSAL.PS
    
    # Construct the JSON request payload as a PowerShell object
    $jsonObject = @{
        Filters = @(
            @{
                DataModelName = "Date"
                Value = $FromDate
                Operand = 4 # Operand 4: Greater than or equal to
            },
            @{
                DataModelName = "Date"
                Value = $ToDate
                Operand = 6 # Operand 6: Less than or equal to
            }
        )
        Dimensions = @(
            @{ DataModelName = "AutoAttendantIdentity" }
            @{ DataModelName = "AutoAttendantDirectorySearchMethod" }
        )
        Measurements = @(
            @{ DataModelName = "PSTNTotalMinutes" }
            @{ DataModelName = "TotalCallCount" }
        )
        Parameters = @{
            UserAgent = "Power BI Desktop" # Identifies the request source
        }
        LimitResultRowsCount = 100000 # Maximum number of rows to return
    }
    
    # Convert the PowerShell object to a JSON string
    $jsonString = $jsonObject | ConvertTo-Json -Depth 10 -Compress
    
    # Compress the JSON string using Gzip
    $Bytes = $jsonString.ToCharArray() | ForEach-Object { $_ -as [Byte] }
    $MemoryStream = New-Object IO.MemoryStream
    $CompressedStream = New-Object System.IO.Compression.GZipStream ($MemoryStream, [IO.Compression.CompressionMode]::Compress)
    $CompressedStream.Write($Bytes, 0, $Bytes.Length)
    $CompressedStream.Close()
    $Gzip = [Convert]::ToBase64String($MemoryStream.ToArray()) # Convert compressed data to Base64
    $MemoryStream.Close()
    
    # URL-encode the Base64 Gzip string
    $UrlEncoded = [System.Web.HttpUtility]::UrlEncode($Gzip)
    
    # Authenticate and obtain an access token
    $Token = (Get-MsalToken -ClientId $ClientID -TenantId $TennantId -Scopes "https://api.interfaces.records.teams.microsoft.com/.default").AccessToken
    
    # Construct the full API URL with the encoded query
    $URLwithQuery = $URL + $UrlEncoded
    
    # Define the request headers
    $Headers = @{
        Authorization = "Bearer $Token" # Include the access token in the Authorization header
    }
    
    # Send the API request and capture the response
    $response = Invoke-RestMethod -Uri $URLwithQuery -Headers $Headers -Method Get
    
    # Output the response data
    $response.dataResult
    
    

    Was this answer helpful?

    1 person found this answer helpful.

  2. notthisagain 0 Reputation points
    2025-07-03T08:37:31.9333333+00:00

    Hi Brian, could you please break this down for me as I don't get it..Why are you using the clientID = application ID if you are probably passing User credentials, I assume username and password? Or what do you have in the credential object? I don't get the logic of using application registration with additional credentials?

    I'm using an application ID and client secret, how would I need to change the request for access token, or is it at all possible with MsalToken?

    Thank you!

    $Token = (Get-MsalToken -ClientId $ClientID -TenantId $TennantId -Scopes "https://api.interfaces.records.teams.microsoft.com/.default" -UserCredential $mycred).AccessToken 
    
    

    Was this answer helpful?


  3. Dean Krueger 0 Reputation points
    2025-06-26T11:54:09.91+00:00

    If you are looking for something like this, I can give you, my query. I export this and use a pivot table to render the totals of each agent.image

    Was this answer helpful?


  4. GIAMPAOLO PITZALIS 0 Reputation points
    2025-02-10T16:50:05.6966667+00:00

    Hi Brian,

    As far as I can see from your script, you are using the "password" grant type (-UserCredential $mycred) when requesting the token. This worked for me as well.

    This is not a best practice because you need to disable MFA and password expiration for the credentials stored in the XML file.

    I want to use "client_credentials" as the grant type instead.

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.