Newer Version Available
Download Formatted Excel Reports Using the Reports REST API
To execute a report and obtain the results, the Salesforce Lightning Report Builder issues a REST request to the Analytics API. The API is a POST to the endpoint /services/data/vXX.x/analytics/reports/<reportId>.
After the report is created, use a GET request to obtain the results. By default, results are returned in JSON format, which the Report Run page renders. This format is specified in the Accept header information.
Request Excel Output
To request Excel instead of JSON format, change the Accept value in the request header to application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.
Now when you execute a GET request, the Excel file is created. The raw response includes the Excel filename, as shown in bold in the following example. You can add code to your application to download the file from the response stream.
1Raw Response
2HTTP/1.1 200 OK
3Date: Wed, 06 Jun 2018 17:23:58 GMT
4Strict-Transport-Security: max-age=31536000; includeSubDomains
5X-Content-Type-Options: nosniff
6X-XSS-Protection: 1; mode=block
7Content-Security-Policy: upgrade-insecure-requests
8Cache-Control: no-cache,must-revalidate,max-age=0,no-store,private
9Set-Cookie: BrowserId=YJXhUq42SRyZ3hhgDPFxog;Path=/;Domain=.salesforce.com;Expires=Sun, 05-Aug-2018 17:23:58 GMT;Max-Age=5184000
10Expires: Thu, 01 Jan 1970 00:00:00 GMT
11Sforce-Limit-Info: api-usage=4/15000
12Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
13Content-Disposition: attachment; filename="New Opportunities Report-2018-05-06-10-23-59.xlsx"
14Transfer-Encoding: chunked