API Endpoint Test UI cannot send JSON requests (Content-Type is always text/plain)

API Endpoint Test UI cannot send JSON requests (Content-Type is always text/plain)

avatar

When testing a PowerShell Universal API endpoint using the built-in Test tab, it is not possible to send a request with the Content-Type: application/json header.
The Test UI only allows adding a header named ContentType, but this does not result in an actual HTTP Content-Type header being sent.
As a result, the request body is not treated as application/json, and parameter binding does not work.

Steps to reproduce
Create an API endpoint like:

param(
    [string]$Subject,
    [string]$Description,
    [string]$Reference
)

 return New-PSUApiResponse -StatusCode 200 -Body $Subject


Open the endpoint's Test tab.
Configure:

  • Method: POST
  • Header:
    • ContentType: application/json
  • Body:
{
  "Subject": "PSU Test",
  "Description": "Description Stuff",
  "Reference": "PSUTEST-2",
}


Click Invoke.

Expected behavior
The request should be sent with:
Content-Type: application/json and the JSON body should be bound to the parameters:
$Subject = "PSU Test"

Actual behavior
Parameter binding fails with an error similar to:
A parameter cannot be found that matches parameter name '{
"Subject":"PSU Test",
...
}'

The same request works correctly when sent externally (e.g. via Invoke-RestMethod, Postman, or curl) with a proper Content-Type: application/json header.

All Comments (1)

avatar

@tools-sebi I've opened an issue to track this problem. I'll update this topic if we need any more information.

Adam Driscoll
PowerShell Expert and Developer at Devolutions