+ Start a Discussion
crtest1crtest1 

How to pass access token when getting Report data

Hi Simon,

 

I'd like to get Salesforce Report data with access token. I used HttpClient to setup connection to Salesforce and send request to get report data. In request header, I used cookies and add 'sid' to it. It works well. However, when I switch to OAuth it doesn't work since then. I tried assigning access token to 'sid' as well as removing 'sid' from header and adding 'Authorization: OAuth #access token#' to header of the request without success. The response code is 200 though. The response is a page with redirect to 'https://login.salesforce.com/?ec=302&startURL=/00O50000002HVb2?isExcel=1&xf=csv&export=1&enc=UTF-8'. Following are the codes for sending the request.

                GetMethod get = new GetMethod(url);
		get.setFollowRedirects(true);
		
		get.setRequestHeader("Cookie", "com.salesforce.LocaleInfo=us; inst=APP7");
		get.setRequestHeader("Authorization: OAuth ", accessToken);
		
		int iCode = client.executeMethod(get);

 Please help take a look, and help to point out what could be wrong.

 

Thanks,

Michael

crtest1crtest1

Here is the curl script that i used for simulating the call.

curl  -k -x myproxy:8080 --request GET ^
  --header "Cookie: com.salesforce.LocaleInfo=us; inst=APP7" ^
  --header "Authorization: OAuth 00D500000006tTs!AREAQOai9.MzQBS__vUAaWV6SYyokLFcxVTCLbrikc9ttJB8rumf4J73lDa2LJ3.uF6Y3xZOT7dSaDeoWC71B3PW9hN45is8" ^
  --header Expect: ^
  --insecure ^
  --verbose ^
  https://na5.salesforce.com/00O50000002HVb2?isExcel=1&export=1&enc=UTF-8&xf=csv

 And following is the response:

<!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>
var escapedHash = '';
var url = 'https://login.salesforce.com/?ec=302&startURL=%2F00O50000002HVb2%3FisExcel%3D1';
if (window.location.hash) {
   escapedHash = '%23' + window.location.hash.slice(1);
}
if (window.location.replace){
window.location.replace(url + escapedHash);
} else {;
window.location.href = url + escapedHash;
}
</script>
</head>
</html>

<!--
...................................................................................................
...................................................................................................
...................................................................................................
...................................................................................................
-->

 

SuperfellSuperfell

Sorry, there's no supported API for accessing report data.

crtest1crtest1

Do you mean there is no supported Webservice API for accessing report data? I'm not using webservice API for report data. I use http connection to request for report data.

 

it works if i pass session id as sid in request header. It doesn't work if I pass access token as 'Authorization: OAuth #access_token#' in request header. So the question is can i use access token to access report data. if so, how can i do that?

 

Thanks,

Michael

BrendanOCBrendanOC

No, you cannot.  You need a full Salesforce.com Session ID.