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
Christian MalpeliChristian Malpeli 

INVALID_SESSION_ID: Session expired or invalid

Hello,

I've seen this topic come up, but I don't see any answers that seem to be relevant to my case.

I am using the Rails restforce Gem to connect to Salesforce.  I am able to connect, pull, update, create data, but after some period of time my session seems to expire with the message "INVALID_SESSION_ID: Session expired or invalid".  

Here is the code I am using to initialize my client:
 
@client = Restforce.new oauth_token: options[:salesforce_token],
      refresh_token: options[:salesforce_refresh_token],
      instance_url:  options[:salesforce_instance_url],
      client_id:     sales_force_client_id,
      client_secret: sales_force_client_secret,
      authentication_callback: Proc.new { |x| Rails.logger.debug x.to_s }

And when I make a request (again after a period of time) I get the following back:
 
url: "https://cs13.salesforce.com/services/data/v38.0/sobjects/Contact"
  method: :post
  headers: {"User-Agent"=>"Faraday v0.9.2", "Content-Type"=>"application/json", "Authorization"=>"OAuth XXXXXXXXXXX"}
  body: "{\"LastName\":\"Test\",\"FirstName\":\"Test \",\"MailingCountry\":\"United States\",\"MailingPostalCode\":\"29464\",\"MailingCity\":\"Mount Pleasant\",\"MailingState\":\"South Carolina\",\"Phone\":\"1-555-555-5555\",\"Business_Contact__c\":true,\"RecordTypeId\":\"01238000000UVfW\"}"
D, [2017-02-06T14:43:14.791977 #99698] DEBUG -- response:
  status: "401"
  headers: {"date"=>"Mon, 06 Feb 2017 19:43:07 GMT", "x-content-type-options"=>"nosniff", "x-xss-protection"=>"1; mode=block", "content-security-policy"=>"reflected-xss block;report-uri /_/ContentDomainCSPNoAuth?type=xss, referrer origin-when-cross-origin", "set-cookie"=>"BrowserId=I2nltdq0SSqJ7KinYQEyMw;Path=/;Domain=.salesforce.com;Expires=Fri, 07-Apr-2017 19:43:07 GMT", "expires"=>"Thu, 01 Jan 1970 00:00:00 GMT", "www-authenticate"=>"Token", "content-type"=>"application/json;charset=UTF-8", "transfer-encoding"=>"chunked", "connection"=>"close"}
  body: "[{\"message\":\"Session expired or invalid\",\"errorCode\":\"INVALID_SESSION_ID\"}]"

Any pointers would be greatly appreciated!
PRABHAKARAN CHOCKALINGAMPRABHAKARAN CHOCKALINGAM
Did you looked at the session policies about how long the session will be active.
Apps -> Manage -> Edit -> Session Policies.
Christian MalpeliChristian Malpeli
Thanks.  Yes I did.  Timeout Value is set to "None" under Session Policies.

Refresh Token policy is "Refresh token is valid until revoked"
PRABHAKARAN CHOCKALINGAMPRABHAKARAN CHOCKALINGAM
Hi Christian,
If you happened to resolve this issue, please share the root cause.
Thanks.
Christian MalpeliChristian Malpeli
Is this the only channel for support on these issues?
PRABHAKARAN CHOCKALINGAMPRABHAKARAN CHOCKALINGAM
I cam across this Post- https://developer.salesforce.com/forums/?id=906F00000008tJzIAI, thought it might help you.