Hello, would appreciate any help.
I am running below code (app registered in AAD with appropriate permissions) I am able to run get queries for eg. get group, get labels etc. but while I try to PATCH a group to apply sensitivity label it fails with error code mentioned below.
$clientId = "1e3b8f87-09e9-4dfe-xxxxxxxxxx"
$tenantName = "xxxxxxxx.onmicrosoft.com"$clientSecret = 'xxxxxxx_XXXXXXX~21-u2d5x'$ReqTokenBody = @{Grant_Type = 'client_credentials'Scope = 'https://graph.microsoft.com/.default'client_Id = $clientIDClient_Secret = $clientSecret}
$TokenResponse = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenantName/oauth2/v2.0/token" -Method POST -Body $ReqTokenBody
$labelId = "226abfea-0102-40b0-a926-8c422f81ce99"$requestBody = @{assignedLabels = @(@{labelId = $($LabelId)})}
$requestBody = $requestBody | ConvertTo-Json
$contentType = "application/json"$apiUrl = "https://graph.microsoft.com/beta/groups/e4ea79de-a11b-4cf3-a8d7-acdb42XXXXX"$assignedlable = Invoke-RestMethod -Uri $apiurl -Headers $Header -ContentType $contentType -Method PATCH -Body $requestBody
ERROR:
Invoke-RestMethod : The remote server returned an error: (401) Unauthorized.
At line:1 char:18
However, if I run the below, it works
Invoke-RestMethod -Uri $apiurl -Headers $Header -Method get