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

[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}] Error in REST API

Hi Team,

When we try to send the REST API request from one salesforce instance (Sandbox) to another salesforce instance (Prod). We are receiving the following error:
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]

HttpRequest req= new HttpRequest(); 
String username = ''; 
String password = 'test123'; 
Blob headerValue = Blob.valueOf(username + ':' + password); 
String authorizationHeader = 'Basic' + EncodingUtil.base64Encode(headerValue);
req.setHeader('Authorization', authorizationHeader); 
Http http = new Http(); 
String url = ',Name,TableEnumOrId,LastModifiedDate+From+WorkflowRule+Where+LastModifiedDate>2016-01-01'; 
req.setEndpoint(url ); 
HttpResponse res = http.send(req); 
System.debug('AAAAAAAA' +res.getBody());

Could you please anyone check and let us know what modifications required on above code.


I dont think you can directly use the basic authentication. REST API's are available through OAuth 2.0 authentication. You will need to first obtain a access token and then use it in query call. For more information you can refer this link (