0

I have a simple Salesforce report that returns basic information about some opportunities such as opportunity id, owner, end date.

I found the simple_salesforce Python module and I am trying to figure out how to run a report given the Report ID. I just want to have the report output as csv and encode as utf-8.

I found the restful function but I do not know how to use it and I cannot find any documentation for it.

2

What you need to be calling is the Reports and Dashboards Execute Sync endpoint.

You can call this endpoint in Python with simple_salesforce like so:

import simple_salesforce

sf = simple_salesforce.Salesforce(username = ... )
report_id = '00O1R000007XXXXUAC' # However you're obtaining your Report Id
report_results = sf.restful('analytics/reports/{}'.format(report_id))

You'll get back a very complex result body, which is documented in the link above as well. The exact path to your detail lines will vary depending upon the structure of the report. If you're running a simple, non-grouped report, your rows will be in results['factMap']['T!T']['rows'], and each row will have a 'dataCells' key, whose value is a list of dicts with label and value pairs.

You can definitely digest that response body into CSV content, but it'll be a lot more straightforward if you're able to just run a SOQL query rather than executing the report.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.