Lately I needed to execute a JSON-RPC call, but had neither Postman nor Insomnia available. I wondered, if Invoke-WebRequest could do the job.

Requesting the SMD is as simple as:

Invoke-WebRequest -Uri 'https://localhost/api/json-rpc/authentication'

Now I needed to send a POST request with some parameters. That needed some further research. After some trial and error I ended up with the following.

$Body = @{
    jsonrpc = '2.0';
    method  = 'authenticate';
    params  = @{
        username = 'arueckauer';
        password = 'F^YgtU)p9Pd3ANTqm@F^sNWFSf9PU}OCg0N0xCC&C8P>=x^6)Hasdh]HHtXQ#dLg'
    };
    id      = [guid]::NewGuid()
} | ConvertTo-Json
Invoke-WebRequest -Uri 'https://localhost/api/json-rpc/authentication' -Method 'POST' -Body $Body

With the help of [guid]::NewGuid() a new UUIDv4 is created for each request. And piping the body object to ConvertTo-Json returns the necessary JSON representation.

Et voilà!