I am trying to retrieve the report. The report URL looks like this https://space.lightning.force.com/lightning/r/Report/00000YTT000TTTY/view

I have checked online and some suggested to change the instance name from space.lightning.force.com to space.salesforce.com but no success changing instance name . https://space.my.salesforce.com/lightning/r/Report/00000YTT000TTTY/view

Used two approaches to download the report

1- Using simple_salesforce library with below mentioned code. The code is not failing but resulting only in report header (no data).

sf = Salesforce(username=u_name, password=u_pass, security_token= s_token)
sf_instance = 'https://space.my.salesforce.com/' 
reportId = '00000YTT000TTTY'
export = '?isdtp=p1&export=1&enc=UTF-8&xf=csv'

sfUrl = sf_instance + reportId + export
response = requests.get(sfUrl,headers=sf.headers, cookies={'sid': sf.session_id})
download_report = response.content.decode('utf-8')
df = pd.read_csv(StringIO(download_report))

2- Using salesforce_reporting library with below mentioned code. With this approach I am getting the report header and the data. But the data is limited to just 2000 rows. while my report has more than 2000 rows.

from salesforce_reporting import Connection, ReportParser

m_sf = Connection(username= u_name, password= u_pass, security_token = s_token)
report_df = pd.DataFrame(ReportParser(report).records_dict())

I have used approach 1 in classic salesforce to reports successfully download the reports but the same code is not working in lightning as explained above.

Can someone please let me know how I can download the complete report. Thanks for all your help everyone, it's greatly appreciated!

  • 1
    Does this answer your question? simple_salesforce Run Report
    – identigral
    Oct 3, 2023 at 20:35
  • The 2k rows limitation - if you have more than 2k rows, you'll have to implement a filter that allows you to fetch all of records in one or more 2k chunks, then use this filter in API calls while fetching records. You'll need to build that code on top of simple_salesforce
    – identigral
    Oct 3, 2023 at 20:37
  • I have visited the link and I am getting 2000 rows using that approach Checked the count by running this code. len(report_results['factMap']['T!T']['rows']) Oct 4, 2023 at 6:11
  • Can you please let me know how to create a custom filter. I believe you are referring to this Download_report_in_chunks I am not able to understand this solution. Is it possible for you to share a simpler one, really appreciate that. Oct 4, 2023 at 6:15
  • salesforce.stackexchange.com/questions/158516/… has an example. You'll need to translate to Python.
    – identigral
    Oct 4, 2023 at 6:24

1 Answer 1


Don't use the old URL hack. There is an actual API you can use. See Execute Sync or Execute Async and Instance Results. At a basic level, use the endpoint provided to you when you log in to the API (instance_url), with the API endpoint of /services/data/v58.0/analytics/reports/:reportId. This will give you all the data you want in an easy-to-use JSON response.

  • Can you please elaborate a bit more or share sample python code. Thanks. Oct 4, 2023 at 11:05
  • @SaqibSohail For more than 2k rows, you have to use the Execute Async function, with an example in the documentation. Use the URLs located there. salesforce-reporting is 7 years old, and doesn't appear to include an async reporting function.
    – sfdcfox
    Oct 4, 2023 at 11:30
  • the doc in the ^ link is a bit ambiguous claiming the API returns data for the same number of records that are available when the report is run in the Salesforce user interface - which would be 2000. I'll take your word for it that the async can return > 2000 rows but it is not obvious
    – cropredy
    Oct 4, 2023 at 18:44
  • @cropredy Grabbing the instance of the report after it was asynchronously run doesn't change the limit, it's still only 2k rows.
    – identigral
    Oct 5, 2023 at 19:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .