Call a JSON API from PowerShell

Powershell

Invoke-RestMethod parses the response for you, so no ConvertFrom-Json step is needed.

$headers = @{ Authorization = "Bearer $token" }
$body = @{ name = 'example' } | ConvertTo-Json

Invoke-RestMethod -Uri 'https://api.example.com/items' `
  -Method Post -Headers $headers -ContentType 'application/json' -Body $body

More in Networking

Random picks