Skip to content

Update/New-MgGroup Overwriting Intended BodyParameter with camelCase keys (schemaExtension Issue) #1327

@MrCaedes

Description

@MrCaedes

This was something that's been driving me around in circles the past hour, until I noticed the discrepancy whilst comparing the Graph Explorer behaviour v the MSGraph cmdlets in debug.

When attempting to update (or create) a group with a schemaExtension, such as below;

$Data = @{
    "example_Metadata" = @{
        "Environment" = "DEV";
        "Role" = "MyTest";
        "GroupOwner" = "JohnDoe"
    } 
}
Update-MgGroup -GroupId ee499fb5-2107-4bcd-b488-945b48d71a74 -BodyParameter $Data

The cmdlet reformats the keys (as passed in the BodyParameter) into camelCase, leading to the data held within being updated to "Null" as opposed to the intended value - as it doesn't match the keys as-is within the schema that has been created.

HTTP Method:
PATCH

Absolute Uri:
https://graph.microsoft.com/v1.0/groups/ee499fb5-2107-4bcd-b488-945b48d71a74

Headers:
SdkVersion                    : graph-powershell/1.9.6,Graph-dotnet-1.25.1
FeatureFlag                   : 00000047
Cache-Control                 : no-store, no-cache
User-Agent                    : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.19044; en-GB),PowerShell/2022.5.1,Update-MgGroup_Update1
Accept-Encoding               : gzip

Body:
{
  "example_Metadata": {
    "groupOwner": "JohnDoe",
    "role": "MyTest",
    "environment": "DEV"
  }
}

This same behaviour is exhibited when attempting to set the data at the same time as the group being created; the data, as provided by the user, should be passed through as-is - as opposed to forced into camelCase.

We can see the lack of application of the additional data, despite a HTTP/204, via the following:

$(Get-MgGroup -GroupId "ee499fb5-2107-4bcd-b488-945b48d71a74" -Property "example_Metadata").AdditionalProperties.example_Metadata | ConvertTo-JSON

Which yields,

{
  "@odata.type": "#microsoft.graph.ComplexExtensionValue"
}

When doing the same operation (i.e., setting the schema extension values) via the Graph Explorer, or directly interacting with Microsoft Graph, it works as intended - where re-running the above returns the correct values;

{
  "@odata.type": "#microsoft.graph.ComplexExtensionValue",
  "Role": "MyTest",
  "GroupOwner": "JohnDoe",
  "Environment": "DEV"
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions