2

I am using following Endpoint url

/services/data/v37.0/analytics/reports/00O280000037Ls3?includeDetails=true

It is working perfect in Workbench. I can see the Raw response. But when I put it in the Apex set Endpoint it returns error

[{"message":"The request body is either invalid or incomplete.","errorCode":"JSON_PARSER_ERROR"}]

Code is here

      String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password;
      Http h = new Http();
      HttpRequest req = new HttpRequest();
      req.setHeader('Authorization', 'Bearer ' + access_Token);
      req.setBody(reqbody);
      req.setMethod('GET');
      req.setEndpoint('https://teeofftech-dev-ed.my.salesforce.com/services/data/v37.0/analytics/reports/00O280000037Ls3?includeDetails=true');
      HttpResponse res = h.send(req); 

      return string.valueOf(res.getbody());
2

Since you are running this from within salesforce and have already logged in, the most convenient way to make this call would be to get the session id from UserInfo:

Http h = new Http(); 
HttpRequest req = new HttpRequest();
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
req.setMethod('GET');
req.setEndpoint('https://teeofftech-dev-ed.my.salesforce.com/services/data/v37.0/analytics/reports/00O280000037Ls3?includeDetails=true');
HttpResponse res = h.send(req); 

return string.valueOf(res.getbody());
|improve this answer|||||
  • Thanks Martin It works. Can you pl tell me is there any way to convert this JSON to csv format? – SFDC shaikh Aug 4 '16 at 11:23
  • There isn't a way of doing it directly as far as I know. Typically the data structures that you get back from the analytics api are too complex for a csv anyways. – martin Aug 4 '16 at 11:38
  • what do you think which is better way to get these reports in csv formats? – SFDC shaikh Aug 4 '16 at 11:43
  • If you are just pulling out raw data, a bulk api query works well. – martin Aug 4 '16 at 11:44
  • If the raw JSON can be handed over to Javascript. We can get a CSV download. – user477 Aug 4 '16 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.