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

Invoke-MGGraphRequest 400 Bad Request #11

Closed
jimmywinberg opened this issue Dec 11, 2023 · 15 comments
Closed

Invoke-MGGraphRequest 400 Bad Request #11

jimmywinberg opened this issue Dec 11, 2023 · 15 comments

Comments

@jimmywinberg
Copy link

Running: Get-WindowsAutopilotInfoCommunity -Online -TenantId $tenantId -AppId $appId -AppSecret $StoredSecret -GroupTag $GroupTagValue

Invoke-MGGraphRequest : GET https://graph.microsoft.com/beta/devices%3F%24skiptoken%XXXXXXXXX
HTTP/1.1 400 Bad Request
Transfer-Encoding: chunked
Vary: Accept-Encoding
Strict-Transport-Security: max-age=31536000
request-id: XXXXXXX
client-request-id: XXXXXXXXX
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"West Europe","Slice":"E","Ring":"5","ScaleUnit":"001","RoleInstance":"AM4PEPF0001511F"}}
Date: Mon, 11 Dec 2023 16:27:42 GMT
Content-Encoding: gzip
Content-Type: application/json
{"error":{"code":"BadRequest","message":"Resource not found for the segment 'devices?$skiptoken=XXXXXXXXXXXXX'.","innerError":{"date":"2023-12-11T16:27:43","request-id":"XXXXXXXXXX","client-request
-id":"XXXXXXXXXXXX"}}}
At C:\Program Files\WindowsPowerShell\Scripts\get-windowsautopilotinfocommunity.ps1:1933 char:35

  • ... Response = (Invoke-MGGraphRequest -Uri $alloutputNextLink -Method Get ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (Method: GET, Re...870d14de1b29
      }:HttpRequestMessage) [Invoke-MgGraphRequest], HttpResponseException
    • FullyQualifiedErrorId : InvokeGraphHttpResponseException,Microsoft.Graph.PowerShell.Authentication.Cmdlets.InvokeMgGraphRequest
      Adding New Device serial XXXXXXXX
      Waiting for 1 of 1 to be imported
@andrew-s-taylor
Copy link
Owner

Looks like it is failing when grabbing the existing devices, might be worth checking the permissions on your app reg

@jimmywinberg
Copy link
Author

jimmywinberg commented Dec 11, 2023 via email

@jimmywinberg
Copy link
Author

jimmywinberg commented Dec 11, 2023 via email

@andrew-s-taylor
Copy link
Owner

Can you try v4.0.4 which I have just uploaded and see if that works? Looks like something has broken in the latest Graph SDK

@jimmywinberg
Copy link
Author

jimmywinberg commented Dec 11, 2023 via email

@act-GH
Copy link

act-GH commented Dec 11, 2023

Can you try v4.0.4 which I have just uploaded and see if that works? Looks like something has broken in the latest Graph SDK

Where can I find v4.0.4? Last I can see if 4.0.3.

@andrew-s-taylor
Copy link
Owner

Should be there now

@act-GH
Copy link

act-GH commented Dec 11, 2023

Thanks I found it on ps gallery but tried the one on github as well. Unfortunately for me the error remains.

Connected to Intune tenant TENANTID using app-based authentication (Azure AD authentication not supported)
Gathered details for device with serial number: DEVICE
Loading all objects. This can take a while on large tenants
Invoke-MGGraphRequest : GET https://graph.microsoft.com/beta/devicemanagement/manageddevices%3F%24skiptoken%3DLastDevic
eName
HTTP/1.1 400 Bad Request
Transfer-Encoding: chunked
Vary: Accept-Encoding
Strict-Transport-Security: max-age=31536000
request-id: aac8940f-
client-request-id: 81f758e3-
x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"East
US","Slice":"E","Ring":"5","ScaleUnit":"000","RoleInstance":"BL4PEPF000001C9"}}
Date: Mon, 11 Dec 2023 18:35:27 GMT
Content-Encoding: gzip
Content-Type: application/json
{"error":{"code":"BadRequest","message":"Resource not found for the segment 'manageddevices?$skiptoken=LastDeviceName%'.","innerError":{"date":"2023-12-11T18:35:27
","request-id":"aac8940f","client-request-id":"81f758e3"}}}
At D:\get-windowsautopilotinfocommunity_4_0_4.ps1:1934 char:35

  • ... Response = (Invoke-MGGraphRequest -Uri $alloutputNextLink -Method Get ...
    • CategoryInfo : InvalidOperation: (Method: GET, Re...691cb852fee6
      }:HttpRequestMessage) [Invoke-MgGraphRequest], HttpResponseException
    • FullyQualifiedErrorId : InvokeGraphHttpResponseException,Microsoft.Graph.PowerShell.Authentication.Cmdlets.Invok
      eMgGraphRequest
      Get-AutopilotDevice : Microsoft.Graph.PowerShell.Authentication.Helpers.HttpResponseException: Response status code
      does not indicate success: BadRequest (Bad Request).
      at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
      At D:\get-windowsautopilotinfocommunity_4_0_4.ps1:2089 char:23
  •         $device = Get-AutopilotDevice | Where-Object {$_.serialNu ...
    
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-AutopilotDevice

@andrew-s-taylor
Copy link
Owner

I'm trying to work out what has broken in 2.0.11 of the auth module.
2.0.10 will work ok if it's urgent

@act-GH
Copy link

act-GH commented Dec 11, 2023

Assuming you mean v2.10.0 of microsoft.graph.authentication, I tried forcing that version and the error remains.

@andrew-s-taylor
Copy link
Owner

Can you try 2.9.1, it definitely works on that version. Something has broken in pagination after that

@act-GH
Copy link

act-GH commented Dec 11, 2023

2.9.1 isnt erroring out immediately but it is taking a lot longer on the 'loading all objects' step than it used to. We have 100k+ devices so Ill give it time. As of last week I had successfully used v3.0.5 of the community script and it must have been using 2.10.0 of graph auth.

@act-GH
Copy link

act-GH commented Dec 11, 2023

I see that the new scripts added delete/update features but appears to require pulling the entirety of our device list. Given the amount of devices we have, this probably will not be good for our use time wise.

Fortunately, reverting to v3.0.5 of the script and specifying 2.10.0 of the graph auth gets us working again.

Ill revisit at a later date to see about updating to the new version.

Thanks for the awesomeness!

@andrew-s-taylor
Copy link
Owner

I've added a "-newdevice" parameter to 4.0.5 which will skip that bit and should speed it up.

Forced a lower auth module as well

@andrew-s-taylor
Copy link
Owner

This should be resolved in the new 2.11.1 graph authentication module

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

No branches or pull requests

3 participants