<?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 change saved search permissions via python SDK? in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/How-to-change-saved-search-permissions-via-python-SDK/m-p/114569#M23962</link>
    <description>&lt;P&gt;Thank you for your comment @dorilevy, however that example does indeed include the correct URL.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"https://localhost:8089/servicesNS/%s/search/saved/searches/%s/acl" % ("admin", ss)
request = urllib2.Request( url )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It's important to remember the app context the saved search resides in otherwise you will run into an issue where the saved search is not found. For example if I had an app named "MYAPP" and a saved search named "MYSEARCH" the url should reflect that.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&lt;A href="https://localhost:8089/servicesNS/admin/MYAPP/saved/searches/MYSEARCH/acl" target="test_blank"&gt;https://localhost:8089/servicesNS/admin/MYAPP/saved/searches/MYSEARCH/acl&lt;/A&gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 01 Feb 2015 16:46:02 GMT</pubDate>
    <dc:creator>Flynt</dc:creator>
    <dc:date>2015-02-01T16:46:02Z</dc:date>
    <item>
      <title>How to change saved search permissions via python SDK?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-change-saved-search-permissions-via-python-SDK/m-p/114567#M23960</link>
      <description>&lt;P&gt;Hey,&lt;/P&gt;

&lt;P&gt;I am looking for a way to change permissions to a saved search via splunk python SDK. &lt;/P&gt;

&lt;P&gt;I tried using the splunklib.client post method:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import splunklib.client as client
app = "app_name"
cred = {"user": "admin", "password": "changeme", "port": 8089, "host": "localhost","owner":"admin"}

service = client.connect(app=app,**cred)
service.post('saved/searches/report_name/acl', sharing="app" )

Traceback (most recent call last):
  File "&amp;lt;stdin&amp;gt;", line 1, in &amp;lt;module&amp;gt;
  File "/usr/lib/python2.6/site-packages/splunk_sdk-1.2.3-py2.6.egg/splunklib/binding.py", line 238, in wrapper
    return request_fun(self, *args, **kwargs)
  File "/usr/lib/python2.6/site-packages/splunk_sdk-1.2.3-py2.6.egg/splunklib/binding.py", line 62, in new_f
    val = f(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/splunk_sdk-1.2.3-py2.6.egg/splunklib/binding.py", line 657, in post
    response = self.http.post(path, all_headers, **query)
  File "/usr/lib/python2.6/site-packages/splunk_sdk-1.2.3-py2.6.egg/splunklib/binding.py", line 1089, in post
    return self.request(url, message)
  File "/usr/lib/python2.6/site-packages/splunk_sdk-1.2.3-py2.6.egg/splunklib/binding.py", line 1109, in request
    raise HTTPError(response)
splunklib.binding.HTTPError: HTTP 404 Not Found -- 
 In handler 'savedsearch': Could not find object id=report_name
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When i try using curl i get no problem:&lt;BR /&gt;
    curl -k -u admin:changeme &lt;A href="https://localhost:8089/servicesNS/admin/app_name/saved/searches/report_name/acl"&gt;https://localhost:8089/servicesNS/admin/app_name/saved/searches/report_name/acl&lt;/A&gt; -d sharing=app&lt;/P&gt;

&lt;P&gt;Maybe i am doing something wrong?  Or maybe there is other way to do it and i am missing it?&lt;/P&gt;

&lt;P&gt;Regards,&lt;BR /&gt;
Dori&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jan 2015 09:10:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-change-saved-search-permissions-via-python-SDK/m-p/114567#M23960</guid>
      <dc:creator>dorilevy</dc:creator>
      <dc:date>2015-01-29T09:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to change saved search permissions via python SDK?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-change-saved-search-permissions-via-python-SDK/m-p/114568#M23961</link>
      <description>&lt;P&gt;I didn't find a way to do with the splunklib.client object, but i was able to pass it using the answer to this question (see @flynt answer):&lt;/P&gt;

&lt;P&gt;&lt;A href="http://answers.splunk.com/answers/144000/modifying-acl-saved-search-permissions-through-rest-api-using-python.html"&gt;http://answers.splunk.com/answers/144000/modifying-acl-saved-search-permissions-through-rest-api-using-python.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Note - Flynt answer is working but the URL there is wrong (or apply to older splunk version). See my comments there.&lt;/P&gt;</description>
      <pubDate>Sun, 01 Feb 2015 12:01:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-change-saved-search-permissions-via-python-SDK/m-p/114568#M23961</guid>
      <dc:creator>dorilevy</dc:creator>
      <dc:date>2015-02-01T12:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to change saved search permissions via python SDK?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-change-saved-search-permissions-via-python-SDK/m-p/114569#M23962</link>
      <description>&lt;P&gt;Thank you for your comment @dorilevy, however that example does indeed include the correct URL.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"https://localhost:8089/servicesNS/%s/search/saved/searches/%s/acl" % ("admin", ss)
request = urllib2.Request( url )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It's important to remember the app context the saved search resides in otherwise you will run into an issue where the saved search is not found. For example if I had an app named "MYAPP" and a saved search named "MYSEARCH" the url should reflect that.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&lt;A href="https://localhost:8089/servicesNS/admin/MYAPP/saved/searches/MYSEARCH/acl" target="test_blank"&gt;https://localhost:8089/servicesNS/admin/MYAPP/saved/searches/MYSEARCH/acl&lt;/A&gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 01 Feb 2015 16:46:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-change-saved-search-permissions-via-python-SDK/m-p/114569#M23962</guid>
      <dc:creator>Flynt</dc:creator>
      <dc:date>2015-02-01T16:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to change saved search permissions via python SDK?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-change-saved-search-permissions-via-python-SDK/m-p/114570#M23963</link>
      <description>&lt;P&gt;Hey @flynt,&lt;/P&gt;

&lt;P&gt;You are correct. i missed the app context (my app is not search, that is why i thought it is mistake). Sorry about it, and again - thanks for the solution.&lt;/P&gt;

&lt;P&gt;Dori &lt;/P&gt;</description>
      <pubDate>Mon, 02 Feb 2015 09:10:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-change-saved-search-permissions-via-python-SDK/m-p/114570#M23963</guid>
      <dc:creator>dorilevy</dc:creator>
      <dc:date>2015-02-02T09:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to change saved search permissions via python SDK?</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/How-to-change-saved-search-permissions-via-python-SDK/m-p/507881#M86436</link>
      <description>&lt;P&gt;You had the right idea to post to /acl, but you need to urlencode the parameters.&lt;/P&gt;&lt;P&gt;The following creates a new EventType then changes the permissions afterwards. There does not appear to be a way to assign the roles with the initial create method. The "/acl" link can be derived from links in the returned Stanza object.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;from urllib.parse import urlencode

newperms = { "perms.read": "role name 1,role name 2, role name 3", 
                     "perms.write": "role name 1, role name 2",
                    "sharing": "app", "owner": "nobody" 
           }
newet = sdk.confs["eventtypes"].create("test_event_type",sharing="app",app="custom_app")
sdk.post("%s/%s" % (newet.links["alternate"], "acl"), body=urlencode(newperms))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jul 2020 16:31:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/How-to-change-saved-search-permissions-via-python-SDK/m-p/507881#M86436</guid>
      <dc:creator>elewis1</dc:creator>
      <dc:date>2020-07-07T16:31:45Z</dc:date>
    </item>
  </channel>
</rss>

