microsoftgraph / msgraph-sdk-powershell

Powershell SDK for Microsoft Graph
https://www.powershellgallery.com/packages/Microsoft.Graph
Other
699 stars 168 forks source link

Update-MgDeviceManagementDeviceConfiguration - androidDeviceOwnerGeneralDeviceConfiguration and kioskModeAppPositions #1538

Closed William-Francillette closed 1 year ago

William-Francillette commented 2 years ago

Hi

I am experiencing an issue with Update-MgDeviceManagementDeviceConfiguration on resource of the type #microsoft.graph.androidDeviceOwnerGeneralDeviceConfiguration and the attribute kioskModeAppPositions

I am using the bodyParameter parameter with a hashtable as value equivalent to this JSON (only used for display during the debugging)

        Update-MgDeviceManagementDeviceConfiguration -BodyParameter $UpdateParameters `
            -DeviceConfigurationId $currentInstance.Id
"kioskModeAppPositions":  [
                                  {
                                      "position":  1,
                                      "item":  {
                                                   "@odata.type":  "#microsoft.graph.androidDeviceOwnerKioskModeApp",
                                                   "package":  "myId2"
                                               },
                                      "@odata.type":  "#microsoft.graph.androidDeviceOwnerKioskModeAppPositionItem"
                                  },
                                  {
                                      "position":  3,
                                      "item":  {
                                                   "@odata.type":  "#microsoft.graph.androidDeviceOwnerKioskModeApp",
                                                   "package":  "myId3"
                                               },
                                      "@odata.type":  "#microsoft.graph.androidDeviceOwnerKioskModeAppPositionItem"
                                  }
                              ],
  "@odata.type":  "#microsoft.graph.androidDeviceOwnerGeneralDeviceConfiguration"

The error is the followed

{
  "_version": 3,
  "Message": "The Item field is required. - Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 - Activity ID: 76831ba1-129f-430a-8a7a-9f4e75df21ed - Url: 
https://fef.amsua0102.manage.microsoft.com/DeviceConfiguration_2209/StatelessDeviceConfigurationFEService/deviceManagement/deviceConfigurations%28%2711aef5cc-201b-4c61-bfc9-629cf1678352%27%29?api-version=5022-06-20 - 
CustomApiErrorPhrase: DeviceConfigurationValidationErr",
  "CustomApiErrorPhrase": "DeviceConfigurationValidationErr",
  "RetryAfter": null,
  "ErrorSourceService": "",
  "HttpHeaders": "{}"
}

I have checked the documentation but couldn't figure the right way to build this attribute https://learn.microsoft.com/en-us/graph/api/resources/intune-deviceconfig-androiddeviceownerkioskmodeapppositionitem?view=graph-rest-beta

This is the only attribute I am experiencing an issue with - I was able to consume other complex attributes without issue such as AzureAdSharedDeviceDataClearApps, GlobalProxy, KioskModeApps or ShortHelpText

Thanks, William

peombwa commented 2 years ago

Could please share a redacted -Debug log output for use to investigate:

Update-MgDeviceManagementDeviceConfiguration -BodyParameter $UpdateParameters -DeviceConfigurationId $currentInstance.Id -Debug
William-Francillette commented 2 years ago

@peombwa , sure there is the trace This is the hashtable sent to bodyparameter

$update=@{
    "kioskModeAppPositions"=@(
        @{
            "position"=  1
            "item"=@{
                "package"= "myId2"
            }
        }
        @{
            "position"=  2
            "item"=@{
                "package"= "myId3"
            }
        }
    )
    "@odata.type" = "#microsoft.graph.androidDeviceOwnerGeneralDeviceConfiguration"
}

This is the command

Update-MgDeviceManagementDeviceConfiguration -BodyParameter $Update -DeviceConfigurationId $params.Id -Debug

And there is the debug trace: (can see the item parameter missing from the HTTP request)

DEBUG: [CmdletBeginProcessing]: - Update-MgDeviceManagementDeviceConfiguration begin processing with parameterSet 'Update'.
DEBUG: [Authentication]: - AuthType: 'AppOnly', AuthProviderType: 'ClientCredentialProvider', ContextScope: 'Process', AppName: 'Microsoft365DSC'.
DEBUG: [Authentication]: - Scopes: [Agreement.ReadWrite.All, TeamSettings.ReadWrite.All, TeamMember.Read.All, Policy.Read.ConditionalAccess, DeviceManagementManagedDevices.Read.All, Device.Read.All, Policy.ReadWrite.ConditionalAccess, TeamsTab.Read.All, TeamsActivity.Read.All, TeamM
ember.ReadWriteNonOwnerRole.All, Device.ReadWrite.All, User.ReadWrite.All, TeamsTab.Create, RoleManagement.Read.Directory, Policy.ReadWrite.ApplicationConfiguration, Application.ReadWrite.All, Group.Read.All, TeamworkDevice.ReadWrite.All, Directory.ReadWrite.All, TeamsActivity.Send,
 TeamsTab.ReadWrite.All, MailboxSettings.Read, DeviceManagementServiceConfig.Read.All, Team.Create, Group.ReadWrite.All, Directory.Read.All, User.Read.All, Agreement.Read.All, Tasks.Read.All, DeviceManagementServiceConfig.ReadWrite.All, GroupMember.Read.All, TeamMember.ReadWrite.All
, Organization.ReadWrite.All, DeviceManagementConfiguration.Read.All, Team.ReadBasic.All, Mail.Read, DeviceManagementManagedDevices.ReadWrite.All, TeamSettings.Read.All, User.ManageIdentities.All, Organization.Read.All, RoleManagement.ReadWrite.Directory, GroupMember.ReadWrite.All, 
Tasks.ReadWrite.All, Policy.Read.All, DeviceManagementConfiguration.ReadWrite.All, Application.Read.All, DeviceManagementApps.ReadWrite.All, DeviceManagementApps.Read.All, TeamworkDevice.Read.All, AgreementAcceptance.Read.All].
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PATCH

Absolute Uri:
https://graph.microsoft.com/beta/deviceManagement/deviceConfigurations/11aef5cc-201b-4c61-bfc9-629cf1678352

Headers:

Body:
{
  "@odata.type": "#microsoft.graph.androidDeviceOwnerGeneralDeviceConfiguration",
  "kioskModeAppPositions": [
    {
      "position": 1
    },
    {
      "position": 2
    }
  ]
}

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
BadRequest

Headers:
Transfer-Encoding             : chunked
Vary                          : Accept-Encoding
Strict-Transport-Security     : max-age=31536000
request-id                    : 37d44f93-4718-46a3-8c2a-510fc57ff035
client-request-id             : 37d44f93-4718-46a3-8c2a-510fc57ff035
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"UK South","Slice":"E","Ring":"3","ScaleUnit":"000","RoleInstance":"LN2PEPF00003306"}}
Date                          : Fri, 30 Sep 2022 18:56:35 GMT

Body:
{
  "error": {
    "code": "BadRequest",
    "message": "{\r\n  \"_version\": 3,\r\n  \"Message\": \"The Item field is required. - Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 - Activity ID: 37d44f93-4718-46a3-8c2a-510fc57ff035 - Url: https://fef.amsua0102.manage.microsoft.com/DeviceConfigurati
on_2209/StatelessDeviceConfigurationFEService/deviceManagement/deviceConfigurations%28%2711aef5cc-201b-4c61-bfc9-629cf1678352%27%29?api-version=5022-07-24 - CustomApiErrorPhrase: DeviceConfigurationValidationErr\",\r\n  \"CustomApiErrorPhrase\": \"DeviceConfigurationValidationErr\",
\r\n  \"RetryAfter\": null,\r\n  \"ErrorSourceService\": \"\",\r\n  \"HttpHeaders\": \"{}\"\r\n}",
    "innerError": {
      "date": "2022-09-30T18:56:36",
      "request-id": "37d44f93-4718-46a3-8c2a-510fc57ff035",
      "client-request-id": "37d44f93-4718-46a3-8c2a-510fc57ff035"
    }
  }
}

Update-MgDeviceManagementDeviceConfiguration : {
  "_version": 3,
  "Message": "The Item field is required. - Operation ID (for customer support): 00000000-0000-0000-0000-000000000000 - Activity ID: 37d44f93-4718-46a3-8c2a-510fc57ff035 - Url: 
https://fef.amsua0102.manage.microsoft.com/DeviceConfiguration_2209/StatelessDeviceConfigurationFEService/deviceManagement/deviceConfigurations%28%2711aef5cc-201b-4c61-bfc9-629cf1678352%27%29?api-version=5022-07-24 - CustomApiErrorPhrase: DeviceConfigurationValidationErr",
  "CustomApiErrorPhrase": "DeviceConfigurationValidationErr",
  "RetryAfter": null,
  "ErrorSourceService": "",
  "HttpHeaders": "{}"
}
At line:1 char:1
+ Update-MgDeviceManagementDeviceConfiguration -BodyParameter $Update - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: ({ DeviceConfigu...onfiguration1 }:<>f__AnonymousType199`2) [Update-MgDevice...guration_Update], RestException`1
    + FullyQualifiedErrorId : BadRequest,Microsoft.Graph.PowerShell.Cmdlets.UpdateMgDeviceManagementDeviceConfiguration_Update
DEBUG: [CmdletEndProcessing]: - Update-MgDeviceManagementDeviceConfiguration end processing.
peombwa commented 1 year ago

Thanks for the debug log!

We've traced the bug to how the serializer serializes nested hashtables to JSON.

We will issue a bug fix for this in our next release.