<?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: How to modify an existing scheduled search and enable it via REST API? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-modify-an-existing-scheduled-search-and-enable-it-via/m-p/118829#M24666</link>
    <description>&lt;P&gt;Interesting. Comparing these two docs sections&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.3/RESTAPI/RESTsearch#POST_saved.2Fsearches"&gt;http://docs.splunk.com/Documentation/Splunk/6.1.3/RESTAPI/RESTsearch#POST_saved.2Fsearches&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.3/RESTAPI/RESTsearch#POST_saved.2Fsearches.2F.7Bname.7D"&gt;http://docs.splunk.com/Documentation/Splunk/6.1.3/RESTAPI/RESTsearch#POST_saved.2Fsearches.2F.7Bname.7D&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;only the former should create a search.&lt;/P&gt;

&lt;P&gt;Is the to-be-updated search private, or app-public? If the latter then give POSTing to &lt;CODE&gt;/servicesNS/-/app/saved/searhes/name&lt;/CODE&gt; a shot.&lt;/P&gt;

&lt;P&gt;Have you considered using one of the many Splunk SDKs available? Specifically this: &lt;A href="http://dev.splunk.com/view/python-sdk/SP-CAAAEBB"&gt;http://dev.splunk.com/view/python-sdk/SP-CAAAEBB&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Sep 2014 20:23:14 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2014-09-10T20:23:14Z</dc:date>
    <item>
      <title>How to modify an existing scheduled search and enable it via REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-modify-an-existing-scheduled-search-and-enable-it-via/m-p/118824#M24661</link>
      <description>&lt;P&gt;Hello Experts,&lt;/P&gt;

&lt;P&gt;I'm trying to enable a scheduled search via a rest call. I'm given the name of the search, and when I called something as simple as:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;request = urllib2.Request(base_url + '/servicesNS/' + owner + '/MyApp/saved/searches',
    data = urllib.urlencode({'name': searchname, 'is_scheduled': "1", 'disabled': 0}),
    headers = { 'Authorization': ('Splunk %s' %settings['sessionKey'])})
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The error logs informed that they needed a search string. So I pulled the existing search string and fed it, and then it asked for the cron_schedule, and when I fed it that, it created a new copy of the search, but private. What's the right way to modify an existing search, to just enable it?&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;In response to Martin's question, urllib2 does make a post request when configured with a payload. I can set macros easily by using the following code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;request = urllib2.Request(base_url + '/servicesNS/-/MyApp/properties/macros/' + macroname,
    data = urllib.urlencode({'definition': macrovalue}),
    headers = { 'Authorization': ('Splunk %s' %settings['sessionKey'])})
search_results = urllib2.urlopen(request)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Additionally, I can see the proper paths being followed in the logs (except for the lack of the modification):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;09-09-2014 23:37:08.530 -0700 DEBUG REST_Calls - app=MyApp POST saved/searches id=My Search Name: cron_schedule -&amp;gt; ['9 * * * *'], disabled -&amp;gt; [0], is_scheduled -&amp;gt; [1], search -&amp;gt; [My Search String]
09-09-2014 23:37:08.532 -0700 INFO  SavedSearchAdminHandler - handleEdit called for id="My Search Name"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've also tried mimicing exactly the format of the Macro search above, to no avail:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;request = urllib2.Request(base_url + '/servicesNS/' + owner + '/MyApp/saved/searches/My%20Search%20Name',
    data = urllib.urlencode({'is_scheduled': "1", 'disabled': 0}),
    headers = { 'Authorization': ('Splunk %s' %settings['sessionKey'])})
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Sep 2014 06:45:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-modify-an-existing-scheduled-search-and-enable-it-via/m-p/118824#M24661</guid>
      <dc:creator>David</dc:creator>
      <dc:date>2014-09-10T06:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to modify an existing scheduled search and enable it via REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-modify-an-existing-scheduled-search-and-enable-it-via/m-p/118825#M24662</link>
      <description>&lt;P&gt;Is &lt;CODE&gt;urllib2.Request()&lt;/CODE&gt; making a POST request by default?&lt;/P&gt;</description>
      <pubDate>Wed, 10 Sep 2014 14:54:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-modify-an-existing-scheduled-search-and-enable-it-via/m-p/118825#M24662</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-09-10T14:54:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to modify an existing scheduled search and enable it via REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-modify-an-existing-scheduled-search-and-enable-it-via/m-p/118826#M24663</link>
      <description>&lt;P&gt;Martin, yes it is. Just added a working example (for Macros).&lt;/P&gt;</description>
      <pubDate>Wed, 10 Sep 2014 15:18:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-modify-an-existing-scheduled-search-and-enable-it-via/m-p/118826#M24663</guid>
      <dc:creator>David</dc:creator>
      <dc:date>2014-09-10T15:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to modify an existing scheduled search and enable it via REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-modify-an-existing-scheduled-search-and-enable-it-via/m-p/118827#M24664</link>
      <description>&lt;P&gt;Is the URL called &lt;CODE&gt;.../saved/searches&lt;/CODE&gt; or &lt;CODE&gt;.../saved/searches/name&lt;/CODE&gt;? The former creates a search on POST, the latter updates an existing search on POST.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Sep 2014 15:47:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-modify-an-existing-scheduled-search-and-enable-it-via/m-p/118827#M24664</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-09-10T15:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to modify an existing scheduled search and enable it via REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-modify-an-existing-scheduled-search-and-enable-it-via/m-p/118828#M24665</link>
      <description>&lt;P&gt;For the last block I added, I used /saved/searches/name and it still created a new private one.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Sep 2014 16:19:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-modify-an-existing-scheduled-search-and-enable-it-via/m-p/118828#M24665</guid>
      <dc:creator>David</dc:creator>
      <dc:date>2014-09-10T16:19:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to modify an existing scheduled search and enable it via REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-modify-an-existing-scheduled-search-and-enable-it-via/m-p/118829#M24666</link>
      <description>&lt;P&gt;Interesting. Comparing these two docs sections&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.3/RESTAPI/RESTsearch#POST_saved.2Fsearches"&gt;http://docs.splunk.com/Documentation/Splunk/6.1.3/RESTAPI/RESTsearch#POST_saved.2Fsearches&lt;/A&gt;&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.1.3/RESTAPI/RESTsearch#POST_saved.2Fsearches.2F.7Bname.7D"&gt;http://docs.splunk.com/Documentation/Splunk/6.1.3/RESTAPI/RESTsearch#POST_saved.2Fsearches.2F.7Bname.7D&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;only the former should create a search.&lt;/P&gt;

&lt;P&gt;Is the to-be-updated search private, or app-public? If the latter then give POSTing to &lt;CODE&gt;/servicesNS/-/app/saved/searhes/name&lt;/CODE&gt; a shot.&lt;/P&gt;

&lt;P&gt;Have you considered using one of the many Splunk SDKs available? Specifically this: &lt;A href="http://dev.splunk.com/view/python-sdk/SP-CAAAEBB"&gt;http://dev.splunk.com/view/python-sdk/SP-CAAAEBB&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Sep 2014 20:23:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-modify-an-existing-scheduled-search-and-enable-it-via/m-p/118829#M24666</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-09-10T20:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to modify an existing scheduled search and enable it via REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-modify-an-existing-scheduled-search-and-enable-it-via/m-p/118830#M24667</link>
      <description>&lt;P&gt;I agree.. this absolutely seems like something that should work. This particular search is owned by admin (on my local instance, anyway) and is app-public. I tried using the "-" variant, and that returns a 400 error with an error logged: 09-10-2014 21:18:00.198 -0700 ERROR SavedSearchAdminHandler - Cannot edit/create a saved search for wildcarded users or applications. Pumping up the debug, even the logs say that they're editing the existing search...&lt;/P&gt;</description>
      <pubDate>Thu, 11 Sep 2014 04:29:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-modify-an-existing-scheduled-search-and-enable-it-via/m-p/118830#M24667</guid>
      <dc:creator>David</dc:creator>
      <dc:date>2014-09-11T04:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to modify an existing scheduled search and enable it via REST API?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-modify-an-existing-scheduled-search-and-enable-it-via/m-p/118831#M24668</link>
      <description>&lt;P&gt;Turns out that ultimately there were two problems being faced in the above. The first is the proper endpoint to hit. Rather than hitting the name of the search, the right approach was to provide an empty post to ../saved../searches/Name/enable. The second is that rather than specifying a user, it's necessary to use user context nobody when modifying an existing search. &lt;/P&gt;

&lt;P&gt;Here was the final functioning code:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;request = urllib2.Request(base_url + '/servicesNS/nobody/splunk_search_usage/saved/searches/' + searchname + '/enable', data="",
    headers = { 'Authorization': ('Splunk %s' %settings['sessionKey'])})
search_results = urllib2.urlopen(request)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Sep 2014 05:28:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-modify-an-existing-scheduled-search-and-enable-it-via/m-p/118831#M24668</guid>
      <dc:creator>David</dc:creator>
      <dc:date>2014-09-30T05:28:29Z</dc:date>
    </item>
  </channel>
</rss>

