The following code returns a 200 response when run from Classic (via a js button call to a webservice)
but the same code fails when the webservice method is called from an aura controller I get a 401 response code
HttpRequest request = new HttpRequest();
HttpResponse response = null;
Http http = new Http();
request.setMethod('GET');
request.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
request.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v31.0/analytics/reports/' + this.ReportId + '/describe');
response = http.send(request);
if(response.getStatusCode() != 200) {
throw new InvalidOperationException('ReportFilterQueryBuilder::GetReportFilterFromMetadata Exception Error=Could not access Report Analytics API.');
}
Should I be constructing a different URL when in LEX?
Any help would be appreciated!