[SalesForce] Salesforce REST API Call

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!

Best Answer

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
Related Topic