msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

2.18.0: Invoke-MgGraphRequest Broken

Open bryandam opened this issue 9 months ago • 4 comments

Describe the bug

After upgrading to 2.18.0 (published in PSGallery), some calls using Invoke-MgGraphRequest started getting 400 Bad Requests.

Downgrading to 2.17.0 fixes the issue.

This feels very similar to #2488 in that some character in the filter is causing this issue. Simpler queries, even with filters work.

Expected behavior

The API should return the result if any were found.

How to reproduce

#Fully Uninstall Microsoft.Graph Uninstall-Module Microsoft.Graph -AllVersions Get-InstalledModule Microsoft.Graph.* | ? Name -ne "Microsoft.Graph.Authentication" | Uninstall-Module -AllVersions Uninstall-Module Microsoft.Graph.Authentication -AllVersions

Install-Module Microsoft.Graph -Scope AllUsers -RequiredVersion 2.18.0 -Force

Invoke-MgGraphRequest -Uri "https://graph.microsoft.com/beta/admin/windows/updates/catalog/entries?filter=microsoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions/any(c:c/id eq '10.0.22631.3447')&expand=microsoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions"

Invoke-MgGraphRequest: GET https://graph.microsoft.com/beta/admin/windows/updates/catalog/entries?$filter=microsoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions/any%28c%3Ac/id%2520eq%2520%2710.0.22631.3447%27%29%26expand%3Dmicrosoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions HTTP/2.0 400 Bad Request Vary: Accept-Encoding Strict-Transport-Security: max-age=31536000 request-id: fdbabb05-332c-4c9d-a792-12b98f3674f7 client-request-id: 2f6898b0-f230-4385-bef2-f47766e55557 x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"North Central US","Slice":"E","Ring":"4","ScaleUnit":"004","RoleInstance":"CH01EPF0003521F"}}
Date: Wed, 01 May 2024 20:47:58 GMT Content-Type: application/json Content-Encoding: gzip

{"error":{"code":"BadRequest","message":"Invalid filter clause: Syntax error: character '%' is not valid at position 84 in 'microsoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions/any(c:c/id%20eq%20'10.0.22631.3447')&expand=microsoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions'.","innerError":{"date":"2024-05-01T20:47:58","request-id":"fdbabb05-332c-4c9d-a792-12b98f3674f7","client-request-id":"2f6898b0-f230-4385-bef2-f47766e55557"}}}

#Fully Uninstall Microsoft.Graph Uninstall-Module Microsoft.Graph -AllVersions Get-InstalledModule Microsoft.Graph.* | ? Name -ne "Microsoft.Graph.Authentication" | Uninstall-Module -AllVersions Uninstall-Module Microsoft.Graph.Authentication -AllVersions

Install-Module Microsoft.Graph -Scope AllUsers -RequiredVersion 2.17.0 -Force

Invoke-MgGraphRequest -Uri "https://graph.microsoft.com/beta/admin/windows/updates/catalog/entries?filter=microsoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions/any(c:c/id eq '10.0.22631.3447')&expand=microsoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions"

#succeeds

SDK Version

2.18.0

Latest version known to work for scenario above?

2.17.0

Known Workarounds

No response

Debug output

DEBUG: GET /beta/admin/windows/updates/catalog/entries?filter=microsoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions/any%28c%3Ac/id%2520eq%2520%2710.0.22631.3447%27%29%26expand%3Dmicrosoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions HTTP/1.1 HTTP: graph.microsoft.com User-Agent: Mozilla/5.0 (Windows NT 10.0; Microsoft Windows 10.0.22621; en-US) PowerShell/2024.2.1 Invoke-MgGraphRequest

VERBOSE: received 475-byte response of content type application/json DEBUG: GET https://graph.microsoft.com/beta/admin/windows/updates/catalog/entries?$filter=microsoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions/any%28c%3Ac/id%2520eq%2520%2710.0.22631.3447%27%29%26expand%3Dmicrosoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions HTTP/2.0 400 Bad Request Vary: Accept-Encoding Strict-Transport-Security: max-age=31536000 request-id: 7af7d6f1-99cd-4f5e-b86e-afaeef836db2 client-request-id: 52c522af-8f18-4ac4-9a8e-bb198887ef03 x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"North Central US","Slice":"E","Ring":"4","ScaleUnit":"003","RoleInstance":"CH01EPF000353AC"}} Date: Wed, 01 May 2024 20:46:01 GMT Content-Type: application/json Content-Encoding: gzip

{"error":{"code":"BadRequest","message":"Invalid filter clause: Syntax error: character '%' is not valid at position 84 in 'microsoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions/any(c:c/id%20eq%20'10.0.22631.3447')&expand=microsoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions'.","innerError":{"date":"2024-05-01T20:46:01","request-id":"7af7d6f1-99cd-4f5e-b86e-afaeef836db2","client-request-id":"52c522af-8f18-4ac4-9a8e-bb198887ef03"}}} Invoke-MgGraphRequest: GET https://graph.microsoft.com/beta/admin/windows/updates/catalog/entries?$filter=microsoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions/any%28c%3Ac/id%2520eq%2520%2710.0.22631.3447%27%29%26expand%3Dmicrosoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions HTTP/2.0 400 Bad Request Vary: Accept-Encoding Strict-Transport-Security: max-age=31536000 request-id: 7af7d6f1-99cd-4f5e-b86e-afaeef836db2 client-request-id: 52c522af-8f18-4ac4-9a8e-bb198887ef03 x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"North Central US","Slice":"E","Ring":"4","ScaleUnit":"003","RoleInstance":"CH01EPF000353AC"}} Date: Wed, 01 May 2024 20:46:01 GMT Content-Type: application/json Content-Encoding: gzip

{"error":{"code":"BadRequest","message":"Invalid filter clause: Syntax error: character '%' is not valid at position 84 in 'microsoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions/any(c:c/id%20eq%20'10.0.22631.3447')&expand=microsoft.graph.windowsUpdates.qualityUpdateCatalogEntry/productRevisions'.","innerError":{"date":"2024-05-01T20:46:01","request-id":"7af7d6f1-99cd-4f5e-b86e-afaeef836db2","client-request-id":"52c522af-8f18-4ac4-9a8e-bb198887ef03"}}}

Configuration

Name Value


PSVersion 7.4.2 PSEdition Core GitCommitId 7.4.2 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

Other information

No response

bryandam avatar May 01 '24 20:05 bryandam

I would second the observation, encountering it in an Azure Automation environment with a PowerShell 5.1 runbook querying the v1.0 Graph endpoint for users, devices and other resources. At first, I suspected every query using a filter to fail, but that's actually not the case, without being able to identify a pattern by now Technically, the issue seems to be caused by spaces in URIs to be escaped/encoded twice, resulting in %2520 instead of just %20

I'd gladly provide additional error messages if that would help, but the error messages I encountered look almost identical to the ones already contained in the issue description

EDIT: After reading through #2488 in the meantime, this actually seems to be the exact same issue, just as @bryandam mentioned

DMoenks avatar May 06 '24 13:05 DMoenks

@bryandam @DMoenks kindly update to the latest release 2.19.0 which addressed this issue.

Ndiritu avatar May 09 '24 12:05 Ndiritu

I would confirm it as resolved on my end 👍

DMoenks avatar May 13 '24 10:05 DMoenks

Can confirmed this is also fixed on my end. Thanks for the fix @timayabi2020!

bryandam avatar May 17 '24 12:05 bryandam