Powershell – Converting Curl Request Using Invoke-WebRequest

curlpowershell

I'm struggling to try and convert the following curl request into powershell using invoke-webrequest:

curl -X PATCH "http://172.28.36.62:8080/api/3/http/upstreams/my-api/servers/5" -H "accept: application/json" -H "Content-Type: application/json" -d "{\"down\": false}"

Gone and upgraded nginx and it uses a later version of the API with different commands and struggling to swap them over to powershell.

Best Answer

Assuming your API is a REST API you can use the Invoke-RestMethod PowerShell cmdlet:

Invoke-RestMethod -Uri 'http://172.28.36.62:8080/api/3/http/upstreams/my-api/servers/5' `
    -Method Patch -ContentType 'application/json' -Body '{"down": false}'