1

Hi can someone tell me where i'm going wrong here, i get the following error executing an API call from powershell. I have tried to format the body i many ways but cannot get it to work.

Invoke-RestMEthod : Cannot send a content-body with this verb-type.
At line:7 char:20
+ ... sponseKan = Invoke-RestMEthod -Uri $kanboardserver  -ContentType "app ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Invoke-RestMethod], ProtocolViolationException
    + FullyQualifiedErrorId : System.Net.ProtocolViolationException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

My Code;

  $headersKan = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" -ErrorAction Stop
$headersKan.Add("X-API-Auth", "jsonrpc:$kanboardtoken")
$bodyKan = @{jsonrpc = "2.0"
            id = "1"
            method = "getAllProjects"
            } | ConvertTo-Json
$responseKan = Invoke-RestMEthod -Uri $kanboardserver  -ContentType "application/json"  -Headers $headersKan -Body $bodyKan -ErrorAction Stop
Write-Host $responseKan
1
  • You are not showing all the pertinent code in your post. You have variables that are not defined and not used in your post as well as variable not defined, and used in your post. For example: "jsonrpc:$kanboardtoken" and $kanboardserver. Commented May 26, 2018 at 23:59

1 Answer 1

3

The default http verb is GET which does not allow a body/payload. Pass POST as method argument and do not json-serialize the body yourself.

Sign up to request clarification or add additional context in comments.

2 Comments

yes - start with -Method Post tagged on to the Invoke-RestMethod cmdlet and go from there...
See here for an example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.