A GET request is the simplest API call being made. You can make the call with no additional filter and most API will respond with a small subsection.
We will use the script as an example in the previous page.
#The Client ID from App Registrations
$clientId = "CLIENT_ID"
#The Tenant ID from App Registrations
$tenantId = "TENANT_ID"
#The Client ID from certificates and secrets section
$clientSecret = 'CLIENT_SECRET'
# Construct the authentication URL
$uri = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"
# Construct the body to be used in Invoke-WebRequest
$body = @{
client_id = $clientId
scope = "https://graph.microsoft.com/.default"
client_secret = $clientSecret
grant_type = "client_credentials"
}
# Get Authentication Token
$tokenRequest = Invoke-WebRequest -Method Post -Uri $uri -ContentType "application/x-www-form-urlencoded" -Body $body -UseBasicParsing
# Extract the Access Token
$token = ($tokenRequest.Content | ConvertFrom-Json).access_token
#The Graph API URL
$uri = "https://graph.microsoft.com/v1.0/users"
$method = "GET"
# Run the Graph API query to retrieve users
$output = Invoke-WebRequest -Method $method -Uri $uri -ContentType "application/json" -Headers @{Authorization = "Bearer $token"} -ErrorAction Stop
# Manipulate the JSON object in memory to be human readable
$users = ($users = ($output.Content | ConvertFrom-Json).value)
$users
$uri = "https://graph.microsoft.com/v1.0/users&$filter=userName eq 'j.smith@yahoo.com'"