Get data straight from your Salesforce reports via python using the Analytics API.

The Reports and Dashboards REST API gives you programmatic access to your report and dashboard data as defined in the report builder and dashboard builder. The API lets you integrate the data into any web or mobile application, inside or outside the Salesforce platform.

You can use this data in various ways like below:
• Integrate report data into custom objects.
• Define rich visualizations on top of the API to animate the data.
• Build custom dashboards.
• Automate reporting tasks.
At a high level, the API resources let you query and filter report data. You can:
• Run tabular, summary, or matrix reports synchronously or asynchronously.
• Filter for specific data on the fly.
• Query report metadata.
You can also work with dashboard resources to:
• Get a list of recently used dashboards.
• Get dashboard metadata and data.
• Query dashboard status.
• Refresh dashboards.

Requirements and Limitations:

The Reports and Dashboards REST API is available for any organization that has API enabled. You must establish an authenticated session using OAuth in order to access the Reports and Dashboards REST API. When working with this API, consider these restrictions in addition to general API limits.
Note: Responses and requests are in JSON. While using the Reports and Dashboards REST API with a POST request body, you must use content-type: application/json. You might get unexpected results if you don’t use this content type.

Reports Limits:
• Cross filters, standard report filters, and filtering by row limit are unavailable when filtering data.
• Historical trend reports are only supported for matrix reports.
• The API can process only reports that contain up to 100 fields selected as columns.
• A list of up to 200 recently viewed reports can be returned.
• Your org can request up to 500 synchronous report runs per hour.
• The API supports up to 20 synchronous report run requests at a time.
• A list of up to 2,000 instances of a report that was run asynchronously can be returned.
• The API supports up to 200 requests at a time to get results of asynchronous report runs.
• Your organization can request up to 1,200 asynchronous requests per hour.
• Asynchronous report run results are available within a 24-hour rolling period.
• The API returns up to the first 2,000 report rows. You can narrow results using filters.
• You can add up to 20 custom field filters when you run a report.
Dashboards Limits:
• Your org can request up to 200 dashboard refreshes per hour.
• Your org can request results for up to 5,000 dashboards per hour.
Analytics Notification Limits
• Each user can subscribe to up to 5 reports.
• Each user can create up to 5 Wave notifications.
Note: All limits that apply to reports created in the report builder also apply to the API, as do limits for dashboards created in the dashboard builder. For more information, see “Salesforce Reports and Dashboards Limits” in the Salesforce online help.

Python Script to access salesforce data directly from Report:

#Connect to the Salesforce Analytics API and request data from a report
import salesforce_reporting
import pandas as pd
from salesforce_reporting import Connection, ReportParser


# setup your login details
sf = Connection(username=\'user_name\', password=\'Password\', security_token=\'Security_token\')
#Use the Connection.get_report() method to request report data and then use ReportParser to access all the records
#included in a report (in list format if you use the ReportParser.records() method):

report = sf.get_report(\'report_id\')
parser = salesforce_reporting.ReportParser(report)

parser.records()
df = pd.DataFrame(report)
print(df)

 

2 thoughts on “Get data straight from your Salesforce reports via python using the Analytics API.”

  1. Hi,
    How to define instance name/HostURL of the org in the Connection object?
    There is no Parameter for that in then line: “sf = Connection(us…”

  2. Hi, i’m very new to salesforce , i have tired hard to pass filter but it is not helping me. Could you please show us an example for adding the filter using python to fetch more than 2k records. Much needed help, thanks

Leave a Comment

Your email address will not be published. Required fields are marked *

Select Language »