POST API seems to be broken

Product: PowerShell Universal
Version: 2.10.0

Hi,

after the Update to 2.10.0 all my POST APIs arent working anymore.

I try a simple one:
New-PSUEndpoint -Url “/testpost” -Method “POST” -Endpoint {

ConvertFrom-Json $Body

}

and get:
Invoke-RestMethod http://localhost:5000/testpost -Method Post -Body “{‘username’: ‘adam’}”
Invoke-RestMethod : Der Remoteserver hat einen Fehler zurückgegeben: (400) Ungültige Anforderung.

what can i do?

Revert to 2.9.2 and all APIs are working again.

Invoke-RestMethod http://localhost:5000/testpost -Method Post -Body “{‘username’: ‘adam’}”

username

adam

I can reproduce this. The problem is that, by default, Invoke-RestMethod uses application/www-form-encoded as the content type so it’s trying to translated the body include a form parameter.

You can work around this by specifying the content type in Invoke-RestMethod

Invoke-RestMethod http://localhost:5000/testpost -Method Post -Body “{‘username’: ‘adam’}” -ContentType 'application/json'

This was actually failing in 2.9.3 but the exception was being suppressed. We changed how variables are being set and it caused this issue. I’ve added an integration test to validate this use case and fixed for 2.10.1.