Mark K
Mark K

Reputation: 9378

Python to submit keyword search to Salesforce for results

What would be the proper way to submit search keyword to Salesforce.com and retrieve the search results?

For example, manually with salesforce.com opened in browser, I can key in "manufacturer" in the search box on top of the Salesforce page. That returns all results in different categories like Leads, Accounts, People, Opportunities, Activities etc.

Here, I want to search a keyword "manufacturer", and retrieve the Opportunity Name, URL, Stage, Created Date in the category "Opportunities".

simple-salesforce documentation provides an example, but I don't really understand:

sf.query("SELECT Id, Email FROM Contact WHERE LastName = 'Jones'")

What would be the Python way to submit such searches and return retrievable results including contents, url and dates etc?

Upvotes: 0

Views: 99

Answers (1)

Chase
Chase

Reputation: 5615

The example provided uses SOQL/SOSL for queries, which is what you'll need to use as well if you intend to use the api. In python, you can use urlib.request to send a request with your query to the specified url.

from urllib import request

url = # PUT URL HERE - /vXX.X/search/?q=SOSL search string
response = request.Request(url)

You can now read the response using json module and fetch the info you want.

Unfortunately you did not provide exactly what you want to do, so I cannot provide a full code example

Upvotes: 1

Related Questions