3

I'm just testing the REST Reports & Dashboards API using Workbench and I tried a quick test to download the results in a Formatted Excel format. I used the source code provided in the sample PDF (https://resources.docs.salesforce.com/sfdc/pdf/salesforce_analytics_rest_api.pdf)

Sample GET Request:

/services/data/v42.0/analytics/reports/00OC0000006bLh8

Headers:

Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8 Accept: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

Error Received:

UNSUPPORTED_MEDIA_TYPE errorCode: UNSUPPORTED_MEDIA_TYPE message: The Analytics API only supports JSON content type in both request and response bodies. Specify requests with content type as application/​json.

I feel like this is a very basic rookie error I'm encountering - does anyone have some quick sample code they can share to show me the error of my ways. Thanks!

1 Answer 1

2

In order to use the export as excel feature, you must be on API version 43.0 or higher.

Request

GET /services/data/v43.0/analytics/reports/00O50000005wo2QEAQ HTTP/1.1
Host: ...
Authorization: ...
Accept: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

Response

HTTP/1.1 200 OK
Date: Fri, 15 Jun 2018 18:56:46 GMT
...
Sforce-Limit-Info: api-usage=315/15000
Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Content-Disposition: attachment; filename="Demo-2018-05-15-12-56-47.xlsx"
Transfer-Encoding: chunked
6
  • Thanks for the quick response. I had tried setting the Content-Type already and received the same error - what do you mean Payload must be JSON in this case? I'm already providing the Report ID in the GET request so I didn't think there would be additional payload needed - at least in my Workbench testing. Is the Excel download feature only possible with additional coding?
    – cg13
    Jun 14, 2018 at 21:23
  • @cg13 Sorry, I may have misread the question. If there's no payload, don't include a Content-Type.
    – sfdcfox
    Jun 14, 2018 at 21:26
  • I have been unable to get it to work using Workbench but I built a quick POC in Apex and it works there. I'm unable to move the excel file to an Email attachment - have you found any good online resources for dealing with Excel outputs using the REST API? I've only really been able to find the sample code in the Developer guide and it's pretty sparse.
    – cg13
    Jun 15, 2018 at 18:54
  • @cg13 It apparently only works starting in version 43.0. I got this to work in the workbench: /services/data/v43.0/analytics/reports/00O50000005wo2QEAQ Accept: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet Response: HTTP/1.1 200 OK...Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet Content-Disposition: attachment; filename="Demo-2018-05-15-12-56-47.xlsx"
    – sfdcfox
    Jun 15, 2018 at 18:58
  • @cg13 In the workbench, though you can only log in via 42.0, you can manually change the URL afterwards to 43.0 to get the output. However, workbench doesn't support the Transfer-Encoding: chucked type, so you can't actually see the file. However, simply getting it working should be proof enough that it works.
    – sfdcfox
    Jun 15, 2018 at 19:02

You must log in to answer this question.

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