1

I am using PowerShell and want to convert this curl command in PowerShell. It works well in bash

curl -s -H 'X-AUTH-TOKEN:'09f4a92e8fbfc9f9f530771ac32d37a1'' -H "Content-Type: application/json" -X GET 'http://127.0.0.1/centreon/api/beta/monitoring/services?search=\{"service.state":"2","service.is_acknowledged":"0"\}'

Thanks for your help

Paolo
  • 21,270
  • 6
  • 38
  • 69
Adolf Ku
  • 21
  • 1

2 Answers2

2

Additional headers can be added to the -Headers property as hash table entries:

$result = curl -Uri $uri -ContentType application/json -Method Get -Headers @{'X-AUTH-TOKEN'='09f4a92e8fbfc9f9f530771ac32d37a1'} 

You may want to try converting your uri string to type [System.URI]. This handles standard character replacement like ' ' to %20. I think curl does this already, but it may help you see if something is invalid:

$uri = [System.Uri]::new('http://127.0.0.1/centreon/api/beta/monitoring/services?search=\{"service.state":"2","service.is_acknowledged":"0"\}')

# check the output:
$uri.AbsoluteUri

http://127.0.0.1/centreon/api/beta/monitoring/services?search=%5C%7B%22service.state%22:%222%22,%22service.is_acknowledged%22:%220%22%5C%7D
Cpt.Whale
  • 4,784
  • 1
  • 10
  • 16
  • PowerShell does not accept this part of the uri **{"service.state":"2","service.is_acknowledged":"0"\}'"** – Adolf Ku Aug 25 '21 at 07:20
  • @AdolfKu What version of powershell are you using? It powershell seems to accept it for me, but I don't have the actual webservice to test against. You may want to try converting it to URI first? Added to answer because it's kinda long. – Cpt.Whale Aug 25 '21 at 12:43
0

Here is the solution which worked for me. i have Changed {"service.state":"2","service.is_acknowledged":"0"\}to ==> {"service.state":"2","service.is_acknowledged":"0"}"

Thank you

Adolf Ku
  • 21
  • 1