function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Manoj ThangavelManoj Thangavel 

Lightning component session id invalid or expired

I have lightning component and would like to process the records of list view.

I tried the below callout to get Query, but 
BODY: [{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]

Apex Code: 
 String sessionId = '';
    // Refer to the Page
    PageReference reportPage = Page.SessionIDPage;
    // Get the content of the VF page
    String vfContent = reportPage.getContent().toString();
    System.debug('vfContent '+vfContent);
    // Find the position of Start_Of_Session_Id and End_Of_Session_Id
    Integer startP = vfContent.indexOf('Start_Of_Session_Id') + 'Start_Of_Session_Id'.length(),
    endP = vfContent.indexOf('End_Of_Session_Id');
    // Get the Session Id
    sessionId = vfContent.substring(startP, endP);
    System.debug('sessionId '+sessionId);

HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
Http http = new Http();

String urlInstance = String.valueof(System.URL.getSalesforceBaseURL()).replace('Url:[delegate=','').replace(']','');
String[] instance = urlInstance.split('\\.');
String endPoint = 'https://dc3--dc3dev.my.salesforce.com/services/data/v46.0/sobjects/Contact/listviews/00Br0000001C3QSEA0/describe';
System.debug('The End Point-->' + endPoint);
req.setEndpoint(endPoint);
req.setHeader('Authorization', 'Bearer ' + sessionId);
req.setMethod('GET');
req.setTimeout(20000);

res = http.send(req);

System.debug('BODY: '+res.getBody());
        System.debug('STATUS:'+res.getStatus());
        System.debug('STATUS_CODE:'+res.getStatusCode());

VF page:
<apex:page >
    Start_Of_Session_Id{!$Api.Session_ID}End_Of_Session_Id
</apex:page>

i ref the below Q&A
https://salesforce.stackexchange.com/questions/110515/getting-session-id-in-lightning

Please get me if anything i missed. 
Aakar MehraAakar Mehra
U need to check if ur API is enabled or not in ur salesforce org.
Go to ur Profile--> 'Which profile u are working on'-->Adminsitrative Permissions--> Enable ur Api
This should solve ur problem.
Manoj ThangavelManoj Thangavel
Thanks Akar. The API access was enabled, but I have done the changes in Session settings on unchekingyhe lock session on ip from where originating. 

It's working now, but am not sure the session settings change solved