<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: What is correct format for curl get API Rest call to ITOA in Splunk ITSI</title>
    <link>https://community.splunk.com/t5/Splunk-ITSI/What-is-correct-format-for-curl-get-API-Rest-call-to-ITOA/m-p/439905#M1338</link>
    <description>&lt;P&gt;I got it working. Trick was to specify the $json variable containing the jason payload as "[$json]"&lt;BR /&gt;
I also worked out how to pass secure credentials to the powershell script via the ConvertTo-SecureString method&lt;/P&gt;</description>
    <pubDate>Wed, 13 Feb 2019 00:09:33 GMT</pubDate>
    <dc:creator>perrinj2</dc:creator>
    <dc:date>2019-02-13T00:09:33Z</dc:date>
    <item>
      <title>What is correct format for curl get API Rest call to ITOA</title>
      <link>https://community.splunk.com/t5/Splunk-ITSI/What-is-correct-format-for-curl-get-API-Rest-call-to-ITOA/m-p/439899#M1332</link>
      <description>&lt;P&gt;When I use the example from the &lt;A href="https://docs.splunk.com/Documentation/ITSI/4.0.4/RESTAPI/ITSIRESTAPIreference" target="_blank"&gt;https://docs.splunk.com/Documentation/ITSI/4.0.4/RESTAPI/ITSIRESTAPIreference&lt;/A&gt; to try to retrieve the _key of an ITSI Service with title 296  using the following command&lt;BR /&gt;
curl -k -u admin:password &lt;A href="https://localhost:8089/servicesNS/nobody/SA-ITOA/itoa_interface/service/?fields='title,_key''&amp;amp;'filter='%5C%7Btitle:%22296%22%5C%7D" target="_blank"&gt;https://localhost:8089/servicesNS/nobody/SA-ITOA/itoa_interface/service/?fields='title,_key''&amp;amp;'filter='\{title:"296"\}&lt;/A&gt;'&lt;BR /&gt;
I get a response with an error message which ends in something like this&lt;BR /&gt;
, "sec_grp": "default_itsi_security_group"}]''filter' is not recognized as an internal or external command,operable program or batch file.&lt;BR /&gt;
So  2 questions&lt;BR /&gt;
1 - What is the correct format to use when including the filter command?&lt;BR /&gt;
2 - If the example is incorrect how can I get the _key field of an ISTI service using the title of the service with a Curl REST API command?&lt;BR /&gt;
I want to find the _key from the title so I can disable or delete a specific service.&lt;BR /&gt;
I know my credentials are ok as  the following command returns a JSON payload with the details of the service&lt;BR /&gt;
curl -k -u admin:password &lt;A href="https://localhost:8089/servicesNS/nobody/SA-ITOA/itoa_interface/service/cb448c76-e104-499c-82f1-635628fc0181" target="_blank"&gt;https://localhost:8089/servicesNS/nobody/SA-ITOA/itoa_interface/service/cb448c76-e104-499c-82f1-635628fc0181&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:02:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-ITSI/What-is-correct-format-for-curl-get-API-Rest-call-to-ITOA/m-p/439899#M1332</guid>
      <dc:creator>perrinj2</dc:creator>
      <dc:date>2020-09-29T23:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: What is correct format for curl get API Rest call to ITOA</title>
      <link>https://community.splunk.com/t5/Splunk-ITSI/What-is-correct-format-for-curl-get-API-Rest-call-to-ITOA/m-p/439900#M1333</link>
      <description>&lt;P&gt;Use "" in filter, also after service there is no /:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;curl -k -u admin:password &lt;A href="https://localhost:8089/servicesNS/nobody/SA-ITOA/itoa_interface/service?fields='title,_key''&amp;amp;'filter='\{&amp;quot;title&amp;quot;:&amp;quot;296&amp;quot;\}'" target="test_blank"&gt;https://localhost:8089/servicesNS/nobody/SA-ITOA/itoa_interface/service?fields='title,_key''&amp;amp;'filter='\{"title":"296"\}'&lt;/A&gt;;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Jan 2019 11:54:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-ITSI/What-is-correct-format-for-curl-get-API-Rest-call-to-ITOA/m-p/439900#M1333</guid>
      <dc:creator>p_gurav</dc:creator>
      <dc:date>2019-01-31T11:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: What is correct format for curl get API Rest call to ITOA</title>
      <link>https://community.splunk.com/t5/Splunk-ITSI/What-is-correct-format-for-curl-get-API-Rest-call-to-ITOA/m-p/439901#M1334</link>
      <description>&lt;P&gt;These parameters look off&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;fields='title,_key''&amp;amp;'filter='\{title:"296"\}'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;There’s two  single quotes after the fields parameter when you should have one single quote.  Then there’s a single quote before the word filter which shouldn’t be there.&lt;/P&gt;

&lt;P&gt;Finally the value for filter is surrounded by single quotes which tells bash to “take this literally how I’ve types it” and then you’re trying to escape the curly brackets but your escapes are being taken as literal backslashes because of the single quotes.&lt;/P&gt;

&lt;P&gt;Try this instead&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;fields=“title,_key''&amp;amp;filter=“{title:\"296\”}”
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Jan 2019 12:09:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-ITSI/What-is-correct-format-for-curl-get-API-Rest-call-to-ITOA/m-p/439901#M1334</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2019-01-31T12:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: What is correct format for curl get API Rest call to ITOA</title>
      <link>https://community.splunk.com/t5/Splunk-ITSI/What-is-correct-format-for-curl-get-API-Rest-call-to-ITOA/m-p/439902#M1335</link>
      <description>&lt;P&gt;Thanks for the responses. I did try the suggestions but still get syntax errors. However I've decided I want to do this in Windows PowerShell and won't bother with filters. I can use the PS equivalent of Curl which is Invoke-RestMethod to get the serviceid from the service title by using the following script&lt;BR /&gt;
 $Service = Invoke-RestMethod -Credential perrinj2admin -Uri &lt;A href="https://localhost:8089/servicesNS/nobody/SA-ITOA/itoa_interface/service" target="_blank"&gt;https://localhost:8089/servicesNS/nobody/SA-ITOA/itoa_interface/service&lt;/A&gt;&lt;BR /&gt;
for ($i=0; $i -le $Service.count; $i++) {&lt;BR /&gt;
 if ($Service[$i].title -eq "293"){&lt;BR /&gt;
        $ServiceKey = $Service[$i]._key&lt;BR /&gt;
        $Service = $Service[$i].title&lt;BR /&gt;
    }&lt;BR /&gt;
}&lt;BR /&gt;
 $Service, $ServiceKey&lt;/P&gt;

&lt;P&gt;This works fine but the next step is to disable the service and I've tried the following script&lt;/P&gt;

&lt;P&gt;$service = @{&lt;BR /&gt;
    _key='1132aed7-ba38-498c-98e2-edb29d4144f2'&lt;BR /&gt;
    enabled=0&lt;BR /&gt;
}&lt;BR /&gt;
$json = $service | ConvertTo-Json&lt;BR /&gt;
$response = Invoke-RestMethod -Credential perrinj2admin -Uri '&lt;A href="https://localhost:8089/servicesNS/nobody/SA-ITOA/itoa_interface/service/bulk_update?is_partial_data=1" target="_blank"&gt;https://localhost:8089/servicesNS/nobody/SA-ITOA/itoa_interface/service/bulk_update?is_partial_data=1&lt;/A&gt;' -Method Post -Body $json -ContentType 'application/json; charset=UTF-8'&lt;BR /&gt;
$response&lt;/P&gt;

&lt;P&gt;The response to this is &lt;BR /&gt;
Invoke-RestMethod : {"message":"(400, 'Invalid upsert payload found, must be a valid JSON list.')"}&lt;/P&gt;

&lt;P&gt;I've checked the output of the ConvertTo-Json and it's a valid JSON list.&lt;BR /&gt;&lt;BR /&gt;
Any thoughts on what could be wrong?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:16:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-ITSI/What-is-correct-format-for-curl-get-API-Rest-call-to-ITOA/m-p/439902#M1335</guid>
      <dc:creator>perrinj2</dc:creator>
      <dc:date>2020-09-29T23:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: What is correct format for curl get API Rest call to ITOA</title>
      <link>https://community.splunk.com/t5/Splunk-ITSI/What-is-correct-format-for-curl-get-API-Rest-call-to-ITOA/m-p/439903#M1336</link>
      <description>&lt;P&gt;what is the value of $json before you invoke the rest request?&lt;/P&gt;

&lt;P&gt;write-host $json&lt;/P&gt;</description>
      <pubDate>Thu, 07 Feb 2019 12:03:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-ITSI/What-is-correct-format-for-curl-get-API-Rest-call-to-ITOA/m-p/439903#M1336</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2019-02-07T12:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: What is correct format for curl get API Rest call to ITOA</title>
      <link>https://community.splunk.com/t5/Splunk-ITSI/What-is-correct-format-for-curl-get-API-Rest-call-to-ITOA/m-p/439904#M1337</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;$Username = 'username'
$Password = 'Password'
$pass = ConvertTo-SecureString -AsPlainText $Password -Force
$SecureString = $pass
$MySecureCreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username,$SecureString

$Service = Invoke-RestMethod -Credential $MySecureCreds -Uri 'https://domain.com:8089/servicesNS/nobody/SA-ITOA/itoa_interface/service'
for ($i=0; $i -le $Service.count; $i++) {
 if ($Service[$i].title -eq "${bamboo.buildNumber}"){
        $ServiceKey = $Service[$i]._key
        $Service = $Service[$i].title
    }
}

$service = @{
    _key="$ServiceKey"
    enabled='0'
}
$json = $service | ConvertTo-Json
$response = Invoke-RestMethod -Credential $MySecureCreds -Uri 'https://domain.com:8089/servicesNS/nobody/SA-ITOA/itoa_interface/service/bulk_update?is_partial_data=1' -Method Post -Body "[$json]" -ContentType 'application/json; charset=UTF-8'
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 13 Feb 2019 00:06:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-ITSI/What-is-correct-format-for-curl-get-API-Rest-call-to-ITOA/m-p/439904#M1337</guid>
      <dc:creator>perrinj2</dc:creator>
      <dc:date>2019-02-13T00:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: What is correct format for curl get API Rest call to ITOA</title>
      <link>https://community.splunk.com/t5/Splunk-ITSI/What-is-correct-format-for-curl-get-API-Rest-call-to-ITOA/m-p/439905#M1338</link>
      <description>&lt;P&gt;I got it working. Trick was to specify the $json variable containing the jason payload as "[$json]"&lt;BR /&gt;
I also worked out how to pass secure credentials to the powershell script via the ConvertTo-SecureString method&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 00:09:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-ITSI/What-is-correct-format-for-curl-get-API-Rest-call-to-ITOA/m-p/439905#M1338</guid>
      <dc:creator>perrinj2</dc:creator>
      <dc:date>2019-02-13T00:09:33Z</dc:date>
    </item>
    <item>
      <title>Re: What is correct format for curl get API Rest call to ITOA</title>
      <link>https://community.splunk.com/t5/Splunk-ITSI/What-is-correct-format-for-curl-get-API-Rest-call-to-ITOA/m-p/439906#M1339</link>
      <description>&lt;P&gt;Please remove the sensitive data from your post above (api endpoints).&lt;/P&gt;

&lt;P&gt;Glad you got it working!&lt;/P&gt;

&lt;P&gt;Note it’s best practice to encrypt that password at rest versus leaving it at the top of a script.  You probably know that but I’m mentioning for everyone’s sake.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Feb 2019 00:15:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-ITSI/What-is-correct-format-for-curl-get-API-Rest-call-to-ITOA/m-p/439906#M1339</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2019-02-13T00:15:30Z</dc:date>
    </item>
  </channel>
</rss>

