Saturday, September 2, 2023

Get Teams User's Availability using Microsoft Graph API


Get Teams User's Availability using Microsoft Graph API through Invoke-RestMethod 


```sh
# Import the required modules

Install-Module -Name AzureAD
Install-Module MicrosoftTeams


Import-Module AzureAD
Import-Module MicrosoftTeams

	# Connect to Azure AD
Connect-AzureAD

	# Get an access token for the Graph API
$accessToken = (Get-AzureADToken -Resource "https://graph.microsoft.com").AccessToken

	# Set the Graph API endpoint URL
$graphApiUrl = "https://graph.microsoft.com/v1.0/users//presence"

	# Set the headers for the request
$headers = @{
    "Authorization" = "Bearer $accessToken"
}

	# Send the request to the Graph API and get the response
$response = Invoke-RestMethod -Method Get -Uri $graphApiUrl -Headers $headers

	# Output the presence status of the user
$response.availability
```

No comments:

Post a Comment