Has anybody tried parsing SalesForce report into Pandas DataFrame using Beatbox? There are couple of examples on SO but none of them have provided comprehensive solution or at least what I have perceived it hasn't.
#!/usr/bin/env python3
import beatbox
import pandas as pd
sf = beatbox._tPartnerNS
service = beatbox.Client()
service.serverUrl = 'https://login.salesforce.com/services/Soap/u/38.0'
service.login('my-username', 'my-password')
report_id = '00myreport4G3V'
query = "SELECT Name FROM Report where id = '{}'".format(report_id)
query_result = service.query(query)
This is just selecting the name but ideally I would like to load the content of report into a DataFrame. Any help please?
Report data can be retrieved by Salesforce Reports and Dashboards REST API. This works in Salesforce since Summer'15 (ver 34.0).
I wrote an example with package Simple-salesforce, due to REST API. (It is however possible to rewrite it without simple-salesforce and use an api session from Beatbox, write at least about 10 additional lines of code and install only the requests package.)
Universal code
Usage example
It is possible to dynamically add columns, filters, sorting etc. (docs about report Execute synchronous). The method
to_pandas_dataframeis for a normal tabular report with details and optionally can be with one grand-total and not more than one level of subtotals. It could be possible to retrieve data from more complicated reports (see docs about Decode the Fact Map or a cheatsheet), but it is not implemented because it is easier to remove them on the fly by metadata parameter before running.Only 2000 detailed data rows can be reported. Several requests with filters can be used to see all data.
Fixed code The new code works for any report that contain original rows. It it is not for summary reports without original rows. (The old code worked only for reports with rows and subtotals. Excuse)