Forum Discussion

Danny_B855's avatar
Danny_B855
Copper Contributor
Jun 10, 2020

REST API Request Using Invoke-RestMethod

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?

 

  • Danny_B855's avatar
    Danny_B855
    Copper Contributor

    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 "https://1.2.3.4/api/v1/files/cliScript/incremental" -Headers $headers -Method Put

    Error:
    Invoke-RestMethod : Specified value has invalid CRLF characters.

    • VasilMichev's avatar
      VasilMichev
      MVP

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

Resources