1

I'm trying to automatise the exporting of Salesforce Reports as CSV's, so far I've managed to authenticate in the Salesforce API but I couldn't find any proper documentation on how to export the Salesforce Reports as CSV's or any other examples of doing it.

I've understood that there is a chance that could not be done, but you can still export it as a JSON and convert it to a CSV using a library, although I didn't find anything.

1 Answers1

1

If you're authenticated (got session id back) you're almost there.

The hacky, not officially supported way is to send a GET request to the report export just like user would click a button. Check out How to download a report as a CSV directly from Salesforce Lightning? or Salesforce: Download Reports via URL in R examples (it's not Java but same principle). You'd have to send header that sets cookie with sid=sesionidgoeshere.

The more official way would be to use the reporting API

eyescream
  • 18,088
  • 2
  • 34
  • 46
  • That's perfect thank you, just to make it clear if someone stumbles on this, sessionID = access token. – Valentin-Florin Dumitrache Sep 02 '19 at 11:52
  • That depends a bit on API / login method. In SOAP login call it's called just session id (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_login.htm). If you use REST and OAuth2 then yes, you'll most likely see `access_token` in responses. In Apex and Visualforce it's also "just" session id. And if admin didn't configure something extra in SF security they can be used interchangeably, you can make a link with session id to your java app and the app would impersonate you. Not saying it's a great idea but possible. – eyescream Sep 02 '19 at 12:31
  • There's a major difference, the API is limited to 2000 records unfortunately https://help.salesforce.com/apex/HTViewHelpDoc?id=limits_analyticsapi.htm&language=en_US – milan Jan 06 '21 at 14:39
  • 1
    @milan don't suffer in silence, https://trailblazer.salesforce.com/ideaView?id=0873A000000E9qjQAC – eyescream Jan 06 '21 at 18:16