# Python Script for accessing saved search via XMLRPC

**URL:** <https://integration.keap.com/t/python-script-for-accessing-saved-search-via-xmlrpc/93323>\
**Category:** API Q&A\
**Created:** [November 5, 2024, 3:41pm UTC](https://integration.keap.com/t/python-script-for-accessing-saved-search-via-xmlrpc/93323 "2024-11-05T15:41:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nik\_B](https://avatars.discourse-cdn.com/v4/letter/n/ee59a6/32.png) [@Nik\_B](https://integration.keap.com/u/Nik_B)\
**Post date:** [November 5, 2024, 3:41pm UTC](https://integration.keap.com/t/python-script-for-accessing-saved-search-via-xmlrpc/93323/1 "2024-11-05T15:41:12Z")

</div>

Does anyone have one of these they can share that makes use of the new authorization?

---

<div class="post-metadata">

**Author:** ![Marion\_Dorsett2](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/marion_dorsett2/32/14894_2.png) [@Marion\_Dorsett2](https://integration.keap.com/u/Marion_Dorsett2)\
**Post date:** [November 5, 2024, 4:43pm UTC](https://integration.keap.com/t/python-script-for-accessing-saved-search-via-xmlrpc/93323/2 "2024-11-05T16:43:16Z")

</div>

@Nik_B Download the Postman app, and you can use the XMLRPC documentation to build the Python code for you.

I’m not a Python developer, but using Postman I was able to generate this code:

```auto
import http.client

conn = http.client.HTTPSConnection("api.infusionsoft.com")
payload = "<?xml version=\"1.0\"?>\r\n<methodCall>\r\n <methodName>SearchService.getSavedSearchResultsAllFields</methodName>\r\n <params>\r\n <param>\r\n <value><string>SAK_GOES_HERE</string></value>\r\n </param>\r\n <param>\r\n <value><int>SAVED_SEARCH_ID</int></value>\r\n </param>\r\n <param>\r\n <value><int>USER_ID</int></value>\r\n </param>\r\n <param>\r\n <value><int>0</int></value>\r\n </param>\r\n </params>\r\n</methodCall>"
headers = {
  'X-Keap-API-Key': 'SAK_GOES_HERE',
  'Content-Type': 'application/xml'
}
conn.request("POST", "/crm/xmlrpc/v1", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))

```

Search for these strings and replace them w/ your values:

SAK\_GOES\_HERE = Your Keap SAK  
SAVED\_SEARCH\_ID = The numerical ID of the saved search  
USER\_ID = The user id

[https://developer.keap.com/docs/xml-rpc/#search-retrieve-a-complete-report-from-a-saved-search](https://developer.keap.com/docs/xml-rpc/#search-retrieve-a-complete-report-from-a-saved-search)  
All of the request details are listed here.

To get the search Id, I use the inspector on the browser to find the Id relevant saved search that I want.

---

<div class="post-metadata">

**Author:** ![Nik\_B](https://avatars.discourse-cdn.com/v4/letter/n/ee59a6/32.png) [@Nik\_B](https://integration.keap.com/u/Nik_B)\
**Post date:** [November 5, 2024, 7:50pm UTC](https://integration.keap.com/t/python-script-for-accessing-saved-search-via-xmlrpc/93323/3 "2024-11-05T19:50:45Z")

</div>

thank you marion! i also need the piece to get the oauth token

---

<div class="post-metadata">

**Author:** ![Marion\_Dorsett2](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/marion_dorsett2/32/14894_2.png) [@Marion\_Dorsett2](https://integration.keap.com/u/Marion_Dorsett2)\
**Post date:** [November 5, 2024, 8:14pm UTC](https://integration.keap.com/t/python-script-for-accessing-saved-search-via-xmlrpc/93323/4 "2024-11-05T20:14:28Z")

</div>

I think I see the confusion. When they announced the sunsetting for the legacy API key, the documentation said to use the header: X-Keap-API-Key with the PAK or SAK.

When looking at the latest documentation it’s showing the “Authorization” header passing “Bearer ProvideYourKeyHere” as the value.

So the code I provided will work, or you can update the header and replace it to match the current docs:

‘Authorization’: ‘Bearer ProvideYourKeyHere’,

[https://developer.infusionsoft.com/pat-and-sak/](https://developer.infusionsoft.com/pat-and-sak/)

The XMLRPC doesn’t use the OAuth authentication. You just need to create a Service Account Key to replace the old Legacy API key. If you’re already using the the OAuth API there isn’t a new authorization method, so everything “should” still work.

---

<div class="post-metadata">

**Author:** ![Nik\_B](https://avatars.discourse-cdn.com/v4/letter/n/ee59a6/32.png) [@Nik\_B](https://integration.keap.com/u/Nik_B)\
**Post date:** [November 5, 2024, 8:15pm UTC](https://integration.keap.com/t/python-script-for-accessing-saved-search-via-xmlrpc/93323/5 "2024-11-05T20:15:50Z")

</div>

got it. yes that is confusing on the site. ty

---

<div class="post-metadata">

**Author:** ![bradb](https://sea1.discourse-cdn.com/flex019/user_avatar/integration.keap.com/bradb/32/13_2.png) [@bradb](https://integration.keap.com/u/bradb)\
**Post date:** [November 6, 2024, 9:27pm UTC](https://integration.keap.com/t/python-script-for-accessing-saved-search-via-xmlrpc/93323/6 "2024-11-06T21:27:12Z")

</div>

It accepts both headers right now. We have standardized on using the Authorization header going forward to support better SDK generation which will be coming in the future.
