Welcome Forums General PowerShell Q&A Equivalent notation for Curl -d option

Viewing 1 reply thread
  • Author
    • #168292
      Topics: 60
      Replies: 90
      Points: 36
      Rank: Member

      I am looking to automateĀ  the Check_MK api.

      From the documentation they are using linux examples and I am trying to translate to the example into a powershell context:


      curl "http://myserver/mysite/check_mk/webapi.py?action=get_host&_username=automation&_secret=myautomationsecret&output_format=json&request_format=json" -d 'request={"hostname":"myserver123"}'

      This is just one example.

      -d 'request={"hostname":"myserver123"}'

      I thought i might send it json

      $body= new-object -TypeName psobject -Property @{
          hostname= "server"
       $overarchingobject| Add-Member -Name attributes -Value $body -MemberType NoteProperty
      $json =$overarchingobject | ConvertTo-Json
      Invoke-RestMethod -uri $url  -Body $body -Method post -Verbose

      However the website doesnt seem to recognise the syntax that I give it.


      Any help appreciated as to what is the equivalent format for curl -d in powershell. Thanks in advance šŸ™‚

    • #168304
      Senior Moderator
      Topics: 8
      Replies: 1158
      Points: 4,045
      Helping Hand
      Rank: Community Hero

      You have to pass $json as its is the converted content to post and the key name is request in curl the example not attributes

      $body = new-object -TypeName psobject -Property @{
          hostname = "server"
      $overarchingobject| Add-Member -Name request-Value $body -MemberType NoteProperty
      $json = $overarchingobject | ConvertTo-Json
      Invoke-RestMethod -uri $url  -Body $json  -Method post -Verbose
Viewing 1 reply thread
  • The topic ‘Equivalent notation for Curl -d option’ is closed to new replies.