Equivalent notation for Curl -d option

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

This topic contains 1 reply, has 2 voices, and was last updated by

Senior Moderator
1 month, 3 weeks ago.

  • Author
  • #168292

    Topics: 59
    Replies: 89
    Points: 14
    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: 1041
    Points: 3,439
    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

You must be logged in to reply to this topic.