Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"The DisplayName field is required" - Capital sensitivity with displayName property #2187

Closed
tehmichael opened this issue Jul 25, 2023 · 3 comments · Fixed by #2205
Closed
Assignees
Labels

Comments

@tehmichael
Copy link

Hello!

Receiving 400 BadRequest errors while building new policies with the displayName property when the property name isn't capitalized correctly. We're seeing this with every version 2.0+ cmdlet we've used so far. As soon as we capitalize the correct character, the requests will succeed.

We expect these requests to succeed as they did in previous versions

Example:

New-MgBetaDeviceManagementNotificationMessageTemplate -BodyParameter $( (MgBetaDeviceManagementNotificationMessageTemplate)[0].ToJsonString() | ConvertFrom-Json -AsHashtable ) -Debug

Example JSON:

{
  "brandingOptions": "includeCompanyLogo,includeCompanyName,includeContactInformation",
  "defaultLocale": "en-us",
  "displayName": "Android Non-Compliance Notification",
  "lastModifiedDateTime": "2023-07-20T18:55:07.0000000Z",
  "roleScopeTagIds": [ "0" ]
}

Will return error:

New-MgBetaDeviceManagementNotificationMessageTemplate_Create: The request is invalid.

Status: 400 (BadRequest)
ErrorCode: 
Date: 2023-07-25T18:33:33

Debug reveals the issue in the message:

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
POST

Absolute Uri:
https://graph.microsoft.us/beta/deviceManagement/notificationMessageTemplates

Headers:
FeatureFlag                   : 00000043
Cache-Control                 : no-store, no-cache
User-Agent                    : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.22621; en-US),PowerShell/2023.6.0
Accept-Encoding               : gzip
SdkVersion                    : graph-powershell-beta/2.1.0
client-request-id             : 510efe78-5a64-4925-abb5-1432c0b88e6f

Body:
{}


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

Status Code:
BadRequest

Headers:
Transfer-Encoding             : chunked
Vary                          : Accept-Encoding
Strict-Transport-Security     : max-age=31536000
request-id                    : 7e8844c3-830a-44df-a6b1-3c20c78feded
client-request-id             : 510efe78-5a64-4925-abb5-1432c0b88e6f
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"USGov Arizona","Slice":"E","Ring":"5","ScaleUnit":"001","RoleInstance":"PH1NEPF00008CCC"}}
Date                          : Tue, 25 Jul 2023 18:33:32 GMT

Body:
{
  "error": {
    "code": "",
    "message": "The request is invalid.",
    "innerError": {
      "message": "notificationMessageTemplate.DisplayName : The DisplayName field is required.\r\n",
      "date": "2023-07-25T18:33:33",
      "request-id": "7e8844c3-830a-44df-a6b1-3c20c78feded",
      "client-request-id": "510efe78-5a64-4925-abb5-1432c0b88e6f"
    }
  }
}

Another exaple:
New-MgBetaDeviceManagementGroupPolicyConfiguration -BodyParameter $( $json | ConvertFrom-Json -AsHashtable ) -Debug

Output:

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
POST

Absolute Uri:
https://graph.microsoft.us/beta/deviceManagement/groupPolicyConfigurations

Headers:
FeatureFlag                   : 00000043
Cache-Control                 : no-store, no-cache
User-Agent                    : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.22621; en-US),PowerShell/2023.6.0
Accept-Encoding               : gzip
SdkVersion                    : graph-powershell-beta/2.1.0
client-request-id             : 3fcf583a-e5fa-4a40-b76e-2a0aa60ab26e

Body:
{
  "@odata.context": "https://graph.microsoft.us/beta/$metadata#deviceManagement/groupPolicyConfigurations/$entity"
}


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

Status Code:
BadRequest

Headers:
Transfer-Encoding             : chunked
Vary                          : Accept-Encoding
Strict-Transport-Security     : max-age=31536000
request-id                    : be49d50e-ace6-4193-9286-19fb52f993be
client-request-id             : 3fcf583a-e5fa-4a40-b76e-2a0aa60ab26e
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"USGov Arizona","Slice":"E","Ring":"5","ScaleUnit":"001","RoleInstance":"PH1NEPF00008CCD"}}
Date                          : Tue, 25 Jul 2023 18:54:48 GMT

Body:
{
  "error": {
    "code": "",
    "message": "The request is invalid.",
    "innerError": {
      "message": "configuration.DisplayName : The DisplayName field is required.\r\n",
      "date": "2023-07-25T18:54:48",
      "request-id": "be49d50e-ace6-4193-9286-19fb52f993be",
      "client-request-id": "3fcf583a-e5fa-4a40-b76e-2a0aa60ab26e"
    }
  }
}


New-MgBetaDeviceManagementGroupPolicyConfiguration_Create: The request is invalid.

Status: 400 (BadRequest)
ErrorCode: 
Date: 2023-07-25T18:54:48

Headers:
Transfer-Encoding             : chunked
Vary                          : Accept-Encoding
Strict-Transport-Security     : max-age=31536000
request-id                    : be49d50e-ace6-4193-9286-19fb52f993be
client-request-id             : 3fcf583a-e5fa-4a40-b76e-2a0aa60ab26e
x-ms-ags-diagnostic           : {"ServerInfo":{"DataCenter":"USGov Arizona","Slice":"E","Ring":"5","ScaleUnit":"001","RoleInstance":"PH1NEPF00008CCD"}}
Date                          : Tue, 25 Jul 2023 18:54:48 GMT

Module versions:

Get-Module microsoft.graph*

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.1.0                 Microsoft.Graph.Authentication      {Add-MgEnvironment, Connect-MgGraph, Disconnect-MgGraph, Get-MgContext…}
Script     2.1.0                 Microsoft.Graph.Beta.DeviceManagem… {Get-MgBetaAdminEdge, Get-MgBetaAdminEdgeInternetExplorerMode, Get-MgBetaAdminEdgeInternetExplorerModeSi…
Script     2.1.0                 Microsoft.Graph.Beta.DeviceManagem… {Add-MgBetaDeviceManagementAndroidManagedStoreAccountEnterpriseSettingApp, Add-MgBetaDeviceManagementGro…
Script     2.1.0                 Microsoft.Graph.Beta.DeviceManagem… {Get-MgBetaDeviceManagementApplePushNotificationCertificate, Get-MgBetaDeviceManagementAuditEvent, Get-M…

psversiontable

Name                           Value
----                           -----
PSVersion                      7.3.6
PSEdition                      Core
GitCommitId                    7.3.6
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
@ghost ghost added the ToTriage label Jul 25, 2023
@tehmichael
Copy link
Author

Actually, noticing quite a few parameters needing capitalization besides DisplayName - but creation in the examples above was hung up on having AT LEAST DisplayName. The second cmdlet above (New-MgBetaDeviceManagementGroupPolicyConfiguration -BodyParameter $( $json | ConvertFrom-Json -AsHashtable ) -Debug) had three parameters laid out in JSON (displayName,description and roleScopeTagIds).

@peombwa
Copy link
Member

peombwa commented Jul 26, 2023

Thanks for bringing this to our attention.

The issue is caused by a breaking change that happened in ConvertFrom-Json -AsHashtable as of PowerShell 7.3 - PowerShell/PowerShell#19928. ConvertFrom-Json -AsHashtable now returns a case sensitive OrderedHashtable, which results in the code generator not serializing the properties in the request body:

Body:
{}

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

As workaround, you can consider converting the OrderedHashtable back to a case insensitive Hashtable as suggested at PowerShell/PowerShell#19928 (comment):

$json | ConvertFrom-Json -AsHashtable
$hashTable = [HashTable]::New($json, [StringComparer]::OrdinalIgnoreCase)
New-MgBetaDeviceManagementNotificationMessageTemplate -BodyParameter $hashTable -Debug

We will use this issue to track adding native serialization of OrderedHashtable to SDK.

@peombwa peombwa added Bug and removed ToTriage labels Jul 26, 2023
@peombwa peombwa self-assigned this Jul 26, 2023
@UselessGuru
Copy link

$json | ConvertFrom-Json -AsHashtable
$hashTable = [HashTable]::New($json, [StringComparer]::OrdinalIgnoreCase)
New-MgBetaDeviceManagementNotificationMessageTemplate -BodyParameter $hashTable -Debug

is a poor workaround because it results in a non-ordered hash table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants