Pcornel
Browse topics
Options
Recent
Favorites
Automation · Technical reference

REST APIs

Direct answer

PowerShell calls REST APIs with Invoke-RestMethod, which converts JSON responses to objects, supports headers, bodies, authentication and, in PowerShell 7, retries with -MaximumRetryCount.

When to use this

Use this when PowerShell calls REST APIs.

First 30 seconds

1. Invoke-RestMethod parses JSON into objects.

2. Set timeouts.

3. Handle errors and status codes.

4. Paginate.

5. Don't skip certificate checks in production.

Operational verification

request → API → JSON → objects

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
PowerShell 7.5/current
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformPowerShell 7.5/current · Automation implementations are tool and platform specific. Use the adjacent Domain for the technology being automated and this Domain for automation behavior.
Scope / prerequisiteUse this when PowerShell calls REST APIs.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

3 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Verification path Verify boundary

Start with a read-only request, capture status plus key headers and inspect the returned object structure. For changes, retain the server's resource/operation identifier and perform a follow-up GET or status request until the documented terminal state is reached. Verify paging so a successful first page is not mistaken for a complete inventory.

Step 2 Common mistakes Narrow the fault
  • Invoke-RestMethod without error handling.
Step 3 Where it fails Narrow the fault

DNS/TLS/network failure, HTTP authentication, API authorization, schema validation, rate limiting and eventual target convergence are distinct boundaries. A parsed response is not evidence the full collection was retrieved or a mutation converged. Keep raw protocol facts and PowerShell object interpretation separately observable.

Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points
  • Invoke-RestMethod parses JSON responses into objects.
  • Pass headers and body explicitly.
  • PowerShell 7 supports retries.
Key checks
  • Invoke-RestMethod -Uri <api> -Headers @{Authorization="Bearer $t"} -TimeoutSec 30 — REST call
  • -StatusCodeVariable / try catch for errors — handling
  • Pagination loops — completeness
ReferenceWhy it matters1 section · depth on demand

In depth

Invoke-RestMethod calls REST APIs and converts JSON responses into PowerShell objects automatically; Invoke-WebRequest returns the raw response with status code and headers when you need them.

$h = @{ Authorization = "Token $token"; Accept = 'application/json' }
$devices = Invoke-RestMethod -Uri "$nb/api/dcim/devices/?site=oslo&limit=1000" -Headers $h
$devices.results | Select-Object name, @{n='ip';e={$_.primary_ip4.address}}

$body = @{ vid = 30; name = 'VOICE'; site = @{ slug = 'oslo' } } | ConvertTo-Json -Depth 5
Invoke-RestMethod -Method Post -Uri "$nb/api/ipam/vlans/" -Headers $h -ContentType 'application/json' -Body $body

PowerShell 7 adds -FollowRelLink for paginated APIs, -StatusCodeVariable, -MaximumRetryCount and -RetryIntervalSec. Set -Depth on ConvertTo-Json — the default (2) silently truncates nested objects.

ReferenceImportant terms & boundaries1 section · depth on demand

PowerShell mechanics

Invoke-RestMethod turns HTTP requests and many JSON/XML responses into PowerShell-friendly data, but the authoritative protocol boundary remains HTTP: URI, method, headers, authentication, status code, content type, body and server-side resource semantics. Automatic deserialization is convenient yet can hide raw-response details needed for pagination, rate limits, correlation IDs or vendor error contracts.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.
ReferenceConfiguration & state1 section · depth on demand

Authoring and lifecycle

Model API calls with explicit base URI/version, authentication acquisition, timeout/retry rules and idempotency semantics. Serialize request bodies intentionally with the correct content type, protect tokens from logs, and respect server rate-limit/concurrency guidance. Separate transport retry from business retry so non-idempotent operations are not duplicated blindly.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical examples

Configuration & expected output

Concrete examples are shown only when the stored reference contains an actual configuration or output shape for this Topic.

Configuration example

PowerShell 7.5/current 7.5/currentMinimal authored PowerShell pattern for REST APIs

Assumptions: Review target identity, permissions and environment before mutation.

$headers = @{ Authorization = "Bearer $token" }
$result = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor docPowerShell 7.5/current 7.5/current

Microsoft Learn documentation reviewed for bounded PowerShell reference claims. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-7.5 · confidence 94%
Embedded reference data

Quick lookup tables

REST APIs · PowerShell operational reference

Topic-specific PowerShell runtime identity, persistence, verification, output and failure-boundary lookup.

BoundaryREST APIs reference
Runtime identityPowerShell edition/version + command/module source
Persistent intentScript/module/config prerequisites under source control
VerificationRead-only discovery → execution evidence → independent target read-back
Output contractStructured objects/streams before formatting
Failure boundarySeparate engine/binding from transport/API/native and target-state failures
Depth when you need it

Deep reference

Healthy vs suspicious evidence

Output interpretation

PowerShell may deserialize JSON/XML into objects while headers/status live elsewhere depending on cmdlet/version options. HTTP 2xx means the HTTP request was accepted/satisfied at that layer; APIs can still report asynchronous work or domain-specific partial results. For failures, preserve status code, safe response metadata and correlation ID rather than logging bearer tokens or secret payloads.

Confirmation

Confirm action

Continue?