There are topics that sound the same, but there's no answer there, really.
I'm trying to export report results into a csv file programmatically from a C# app.
Using Analitics API I'm able to get the report ID that I need. Then I build the following url:
"https://na9.salesforce.com/00OE0000001L8cUMAS/?export=1&enc=UTF-8&xf=CSV"
Then tried to do the following:
WebClient wc = new WebClient();
wc.Headers["Authorization"] = "Bearer " + sForceService.SessionHeaderValue.sessionId;
wc.DownloadFile(URL, Path.Combine(Environment.GetEnvironmentVariable("TEMP"), "report.csv"));
But this saves not the report but the following html file:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<script>
if (this.SfdcApp && this.SfdcApp.projectOneNavigator) { SfdcApp.projectOneNavigator.handleRedirect('https://login.salesforce.com/?ec=302&startURL=%2F00OE0000001L8cUMAS%2F%3Fexport%3D1%26xf%3DCSV%26enc%3DUTF-8'); } else
if (window.location.replace){
window.location.replace('https://login.salesforce.com/?ec=302&startURL=%2F00OE0000001L8cUMAS%2F%3Fexport%3D1%26xf%3DCSV%26enc%3DUTF-8');
} else {;
window.location.href ='https://login.salesforce.com/?ec=302&startURL=%2F00OE0000001L8cUMAS%2F%3Fexport%3D1%26xf%3DCSV%26enc%3DUTF-8';
}
</script>
</head>
</html>
<!--
...................................................................................................
...................................................................................................
...................................................................................................
...................................................................................................
-->
Looks like some redirection javascript, so I tried to do WebClient.DownloadFile, passing this redirection url, and this just returns the standard salesforce login screen saying that I need to log in (although, I'm always passing an active sessionId in the header). I don't believe there's no way to programmatically export a report, if I can do it in browser, I should be able to do it from code, I'm just missing something basic... Or is there a way to export the report using Analytics API? I haven't found anything about export in the Analytics API developer guide.