REST API Request Using Invoke-RestMethod

New Contributor

I'm having a devil of time formatting a request to a REST API.  I've tried twenty different ways of passing the request information in headers\body using Invoke-RestMethod. Here's what the request needs to look like:


PUT /api/v1/files/cliScript/incremental
Content-Type: application/octet-stream
<show system uptime>

<show system version>


I can't figure out how to pass these SHOW SYSTEM commands. Has anyone tackled something like this before?


2 Replies

@Danny_B855Here's the last thing I tried:


$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", 'Basic ' + $encodedCreds)
$headers.Add("Content-Type", "application/octet-stream`r`n<show system uptime>`r`n<show system version>")

$Response = Invoke-RestMethod "" -Headers $headers -Method Put

Invoke-RestMethod : Specified value has invalid CRLF characters.

You seem to be passing them as header values, try it with the body of the request instead.