JustAGuy
JustAGuy

Reputation: 5941

Invalid Body using Invoke-Webrequest

I'm trying to post to a Wazuh server using the following guidance: https://documentation.wazuh.com/3.x/user-manual/api/reference.html#add-agent

This is the CURL equivalent:

curl -u foo:bar -k -X POST -d '{"name":"NewHost","ip":"10.0.0.9"}' -H 'Content-Type:application/json' "https://127.0.0.1:55000/agents?pretty"

This is what I've come up using Powershell:

Invoke-WebRequest -Body "{name:'newhost',ip:'10.0.0.9'}" -Uri "http://$($WAZUHSERVER):55000/agents?pretty" -Method Post -Credential $MyCredential -ContentType 'application/json'

I keep getting "Invalid Request Body". I tried alternating with a hash table. No dice. I should mention that I dont have SSL configured so that part is irrelevant.

Upvotes: 0

Views: 576

Answers (1)

JustAGuy
JustAGuy

Reputation: 5941

Found it.

'{"name":"newhost","ip":"10.0.0.0"}'

Using this one as a body worked out perfectly.

Upvotes: 1

Related Questions