+ Start a Discussion

Email Services Context User SessionId Invalid in Callout

I have an email service that processes the emails (creates Contact, Attachment, Task, etc.). It then uses a future callout to send a pointer (Id) to the Attachment that has been created to an external service that retrieves the attached file and performs some detailed processing not possible in Apex.  This external server then logs back into SFDC using stored credentials to update the Contact with additional data.  Ideally, I would like to just pass the session id of the Context User so that we do not need to store credentials externally (some customers do not care for this so much). 
When I use UserInfo.getSessionId() to pass a session id, the external service throws the following error: 
INVALID_SESSION_ID: Invalid Session ID found in SessionHeader: Illegal Session
The external service works just fine when hardcoding a session id from a manually generated source (eg - an onclick javascript link that shows merge field for api session id). 
Is a session id retrieved in this manner (in an email service class with this apex method) not usable when attempting to use it with the web services api from an external server? 
Any help would be greatly appreciated!



We are having the same problem. Did you find a solution?




I am having the same issue, Please let me know if you guys figured out a solution or do you have any work around for getting user session Id in Email Handler class.




we conferred with SFDC and it couldnt even be explained by quite senior techical folks.  we would have preferred to make a synchronous callout, but it wasnt absolutely critical.  so, as workaround, we saved our data to a temp record and used workflow+outbound messaging to the external server to pass all necessary data and a sessionid that works.