sara
sara

Reputation: 31

Update an existing report in SalesForce using simple_salesforce package in python

Given an existing report on SalesForce that I created, can I update the content of the report using simple_salesforce package in python?

# A Pseudo code to get the expected result
from simple_salesforce import Salesforce


sf = Salesforce(username='my_user_name', 
                password='my_password',
                security_token='my_security_token')



export_url = "link to the report I want to change"

session = requests.Session()

response = requests.get(export_url, 
                       headers=sf.headers, 
                       cookies={'sid': sf.session_id})

# this part is pseudo-code, for instance, I want to change a column of the report, I change it and then upload the new version as the current report
response.update(response, data)

Upvotes: 0

Views: 468

Answers (1)

eyescream
eyescream

Reputation: 19637

You're bit out of Simple's comfort zone. You don't manipulate data, you don't even use restful call for "normal" API operations. You just (ab)use simple's login functionality to get the session id and pretend you're a browser. So you can experiment with requests below in Postman for example and then go back to your Python program.

I wonder if you're overcomplicating it. Are you sure you absolutely need a report?

  • Maybe it can be done with a normal SOQL query?
  • There's proper API for reports and a way to filter a report on the fly. It won't save the changes to the report. But that API will return results as JSON, you probably coded your stuff around CSVs.
  • If you need to actually save changes - there are proper Tooling API/Metadata API calls to fetch, modify and deploy back the report definition as XML file. Again - simple might not be best tool for the task, sfdx might fare better.
  • I suspect you'll ignore all these and stick to faking a browser. Google around for "url hacking", for example here. As it becomes more config than code issue - you can find some good stuff in dedicated sister site that has more admins than stackoverflow. For example https://salesforce.stackexchange.com/q/110219/799

Upvotes: 1

Related Questions