I am getting invalid session Id when i try to perform callout using continuation api . If i remove continuation api code and perform a normal callout the the same code is working.
Below is the code
@AuraEnabled(continuation=true cacheable=true)
public static Object continuationapi(){
list<account> ListAccount=new List<account>();
String endPoint = 'callout:SFDC_SRC/services/apexrest/v1/getAccounts/';
Http h2 = new Http();
HttpRequest req1 = new HttpRequest();
req1.setMethod('GET');
req1.setEndpoint(endPoint);
Continuation con = new Continuation(40);
con.continuationMethod='processResponse';
con.state='Hello, World!';
con.addHttpRequest(req1);
system.debug('Action Mehtod con ---'+ con);
return con;
}
@AuraEnabled(cacheable=true)
public static Object processResponse(List<String> labels, Object state) {
HttpResponse response = Continuation.getResponse(labels[0]);
Integer statusCode = response.getStatusCode();
system.debug('Location Details'+response.getHeader('Location'));
system.debug('Status code ----'+ statusCode);
String result = response.getBody();
system.debug('Call back method result --- ' + result);
return result;
}
Target org code
@RestResource(urlMapping='/v1/getAccounts/')
global class FetchAccounts {
@HttpGet
global static list<account> fetchAccount(){
RestRequest req = RestContext.request;
RestResponse res = Restcontext.response;
List<account> listAccount =[Select Id , Name,Industry,Type,AccountNumber from Account LIMIT 3 ];
return listAccount ;
}
}