+ Start a Discussion
Shubham Gupta 93Shubham Gupta 93 

lightning cannot get response from https://rohakela-dev-ed.lightning.force.com/services/data/v37.0/limits

hello guys i basically need to get DataStorageMB from limits api

in lightning when i tried to ran below code 
 
​ Http http = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://rohakela-dev-ed.lightning.force.com/services/data/v37.0/limits');
        req.setHeader(Authorization, 'Bearer '+UserInfo.getSessionId());
        req.setMethod(GET);
        HttpResponse res = http.send(req);
        jsonOutput = res.getBody();
        String loc = res.getHeader('Location');
        system.debug(loc);
        system.debug('outputis '+jsonOutput);
        Map<String, Object> m = (Map<String, Object>) JSON.deserializeUntyped(jsonOutput);

i got 302 error saying resource moved so i added 
String loc = res.getHeader('Location');        
system.debug(loc);

to see which is the new URL its pointing to and it was 
https://rohakela-dev-ed.my.salesforce.com/services/data/v37.0/limits

so i added above url as end point and also added to remote setting.

but doing so as below 
Http http = new Http();
        HttpRequest req = new HttpRequest();
        req.setEndpoint('https://rohakela-dev-ed.my.salesforce.com/services/data/v37.0/limits');
        req.setHeader(Authorization, 'Bearer '+UserInfo.getSessionId());
        req.setMethod(GET);
        HttpResponse res = http.send(req);
        jsonOutput = res.getBody();
        String loc = res.getHeader('Location');
        system.debug(loc);
        system.debug('outputis '+jsonOutput);
        Map<String, Object> m = (Map<String, Object>) JSON.deserializeUntyped(jsonOutput);
but now its showing below error

System.HttpResponse[Status=Unauthorized, StatusCode=401]"|0x14b7be94

outputis [{"message":"This session is not valid for use with the REST API","errorCode":"INVALID_SESSION_ID"}]


 
Shubham Gupta 93Shubham Gupta 93
While going through docs i came to know that Lightning Aura session id diffrers from classsic one and hence authentication is not takiing place,

Please anyone if can guide me