0

I have the following call that works well on postman:

{
   "action": {
      "name": "<action_name>",
      "parameters": [
         {
            "<Parmater1>": "",
            "<Parameter2>": "",
            "from_date": "<date>",
            "to_date":"<date>"
         }
      ],
      "session_token": "xxxx..."}
}

In order to use this call in Powershell I have created the following:

Invoke-restmethod -method Get -uri $Uri -body $body -ContentType "application/json"

but then I receive the following error:

Invoke-restmethod : Cannot send a content-body with this verb-type.

How can I invoke this call without the Body parameter?

How can I send the Parameters as query?

I have also tried using the CURL in powershell:

curl.exe -G GET -H "Content-Type: application/json" -d $data -u $url

and received the following error:

curl.exe : curl: (3) URL using bad/illegal format or missing URL

Error using curl

Amir
  • 1
  • 2
  • 1
    You can't use GET with invoke-webrequest or restmethod combined with a body. Although it is supported in the http standard it isn't supported in these cmdlets (the underlying .net classes used by these cmdlets don't support this). I've encountered the same problem years ago with elasticsearch. – bluuf Jul 24 '22 at 09:51
  • I understand that. the how can I create the same "Get" Call using powershell? – Amir Jul 24 '22 at 14:39
  • Either use a .net class capable of doing webrequests which does support it (I'm unaware of those ones) or use the tcpclient class and create the correct payload yourself. – bluuf Jul 24 '22 at 15:11
  • 1
    Perhaps `curl` (which now also ships with Windows, as `curl.exe`) can perform the call you want. To call it from Windows PowerShell, be sure to call it as `curl.exe`, not just as `curl`, as the latter is a built-in alias for `Invoke-WebRequest`. – mklement0 Jul 24 '22 at 18:11
  • 1
    Thanks @mklement0 I have tried this approach as well but am not familiar with the usage of CURL at all. I have tried to use it but didn't work well. I will add my tries to the question – Amir Jul 24 '22 at 20:26
  • `-u` is for specifying the username and password, not the URL. The target URL needs no option - just try without `-u` – mklement0 Jul 24 '22 at 21:51
  • Sorry @mklement0 still doesn't work - same error i;m affraid. I now added the full error to see whether it might help – Amir Jul 25 '22 at 06:46
  • Replace `-G GET` with `-G` - I suggest consulting the [`curl` man page](https://www.man7.org/linux/man-pages/man1/curl.1.html) (not sure if there's a separate one for `curl.exe` on Windows). – mklement0 Jul 25 '22 at 16:51

0 Answers0