Invoke-RestMethod
Use Invoke-RestMethod to call a REST endpoint and convert the JSON or XML response into PowerShell objects automatically.
Documentation: Microsoft Learn — Invoke-RestMethod
Syntax
See the command anatomy
Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.
Invoke-RestMethod [-Uri] <Uri> [-Method <WebRequestMethod>] [-Headers <IDictionary>] [-Body <Object>] [-ContentType <String>] [-Credential <PSCredential>] [-Authentication <WebAuthenticationType>] [-Token <SecureString>] [-TimeoutSec <Int32>] [<CommonParameters>]- Stage 1Invoke-RestMethod
-Uri -Method -Headers -Body -ContentType -Credential -Authentication -Token -TimeoutSec
Try it
PowerShell example · browser support is limited.
Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.
Follow the objects
Run the command to inspect each stage.
Examples
Invoke-RestMethod -Uri https://api.example.com/items
Show reference output
Sample output · fictional data, shaped like the real thing
id name status -- ---- ------ 1 Server01 healthy 2 Server02 healthy
Invoke-RestMethod -AsSecureString $h
Show reference output
Sample output · fictional data, shaped like the real thing
id name status -- ---- ------ 1 Server01 healthy 2 Server02 healthy
Invoke-RestMethod -Uri $u
Show reference output
Sample output · fictional data, shaped like the real thing
{
"Server": "SRV01",
"Status": "Healthy",
"Checked": "2026-09-10T22:31:00+05:30"
}Parameters
Parameter definitions:
-Uri-Method-Headers-Body-ContentType-Credential-Authentication-Token-TimeoutSec
Practical use and troubleshooting
Practical scenario: Use Invoke-RestMethod when you need to call a REST endpoint and convert the JSON or XML response into PowerShell objects automatically. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.
Common error and fix: A missing property can reflect a different API response shape. Inspect the returned object before selecting fields, and check pagination instead of assuming one response contains all records. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.
See also: Invoke-WebRequest. Invoke-WebRequest exposes an HTTP response including headers and content; Invoke-RestMethod is often more convenient when consuming structured API data. Preserve status and headers when troubleshooting the transport. Read the linked command before substituting it; similar names do not imply identical inputs or output.
Recap
Invoke-RestMethod Use Invoke-RestMethod to call a REST endpoint and convert the JSON or XML response into PowerShell objects automatically.
Next: Invoke-WebRequest