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 = '';
System.debug('The End Point-->' + endPoint);
req.setHeader('Authorization', 'Bearer ' + sessionId);

res = http.send(req);

System.debug('BODY: '+res.getBody());

VF page:
<apex:page >

i ref the below Q&A

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