Lire une API
$m = Invoke-RestMethod 'https://api.open-meteo.com/v1/forecast?latitude=45.76&longitude=4.84¤t=temperature_2m'
$m.current.temperature_2m
Invoke-RestMethod https://api.github.com/repos/microsoft/terminal/releases/latest | Select-Object tag_name, published_at
Envoyer
$corps = @{ content = "Sauvegarde terminée" } | ConvertTo-Json
Invoke-RestMethod -Uri $env:DISCORD_WEBHOOK -Method Post -ContentType 'application/json; charset=utf-8' -Body ([Text.Encoding]::UTF8.GetBytes($corps))
Invoke-RestMethod $url -Headers @{ Authorization = "Bearer $env:API_JETON" }Webhook Discord : créer un webhook.
Télécharger
Invoke-WebRequest 'https://exemple.fr/fichier.zip' -OutFile .\fichier.zipAstuce PowerShell 5 : $ProgressPreference = 'SilentlyContinue' accélère beaucoup les téléchargements. Concepts : API REST.