I am trying to export/download a salesforce to an excel template. The template should be formatted with design and columns similar to the columns in the report. The template is stored as an attachment on a cusObject__c. I am able to export it to excel with visualforce page just fine but I am having issues with formatting there. So I ventured into REST API world. I am very new to APIs and this is my first API class.
public class excelReport {
public excelReport(){
Http http = new http();
HttpRequest request = new HttpRequest();
request.setEndpoint(System.URL.getSalesforceBaseURL().toExternalForm() + '/services/data/v45.0/analytics/reports/00OG00000046KbV');
request.setMethod('GET');
request.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
request.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
HttpResponse response = http.send(request);
if(response.getStatusCode() == 200){
Map<String, Object> results = (Map<String, Object>)
JSON.deserializeUntyped(response.getBody());
System.debug(results);
}
}
}
It have got the report to come back with values but I am not being able to put it in a certain excel file and automatically download.
I have tried:
https://developer.salesforce.com/docs/atlas.en-us.api_analytics.meta/api_analytics/sforce_analytics_rest_api_download_excel.htm
Any help will be appreciated!