<apex:page contentType="application/json">{"sessionId":"{!$Api.Session_ID}"}</apex:page>
Now From your apex class deserialize your vf page to get session id
Apex Class : GetSessionId
public class GetSessionId {
public class SessionId {
public string sessionId;
}
@AuraEnabled
public static string getUserSessionId() {
SessionId sessionJson = new SessionId();
if(!Test.isRunningTest()){
sessionJson = (SessionId)JSON.deserialize(Page.YourVFPage.getContent().toString(), SessionId.class);
}
return sessionJson.sessionId;
}
Hits: 464