Session expiry issue in Salesforce CRM integration

Niharika Raj
Kilo Guru

Hi,

We have implemented Salesforce CRM integration in our instance based on the docs: https://docs.servicenow.com/bundle/rome-it-asset-management/page/product/software-asset-management2/concept/integrate-with-salesforce-crm.html.

We have set the default grant type as 'Resource owner Password credentials' as credentials were shared by the Salesforce team. As specified in the docs link, we were able to click on the 'Get OAuth token' link and retrieve the access token using the username and password+security_token combo. Salesforce team has set the security token lifespan to 6 months.
The job ran successfully that day, however, in the next schedule (the next day), it  failed with the error: Response Received: {"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}.

We tried the below options to fix this:
1. Increased access token lifespan in application registry to 6 months
2. Increased the expiry date in OAuth credentials to 6 months

However, all of the above options didn't work and we had to click on the 'Get OAuth token' link again and had to re-enter the same credentials and only then the job worked.
This is of course, not an ideal way to setup the integration.

Is there a way to fix this issue? Any help would be appreciated.

Regards,

Niharika Raj

1 ACCEPTED SOLUTION

Niharika Raj
Kilo Guru

Hello Patrick,

 

Thanks for the reply. I know this is a very late update, but I just wanted to help anyone who was facing the same issue.

We requested the Salesforce team to reset the credentials, updated the grant type to 'Authorization code' and tried again.

This worked for us and we didn't encounter the session timeout issue.

 

Thanks!

Niharika Raj

View solution in original post

6 REPLIES 6

Thank you.

I appreciate that you found a little time to answer.

 

Have a nice day

/Petr

albert_rio
Tera Contributor

This issue usually happens because the Salesforce session or OAuth token is not being maintained properly between ServiceNow and Salesforce. The error “Session expired or invalid” typically means the access token is not refreshing automatically or the authentication method is not set correctly.

To fix this, you can try a few things. First, switch the OAuth grant type to Authorization Code instead of using username and password, as it handles token refresh better and avoids repeated logins.
Second, make sure your connected app settings allow refresh tokens and set them to stay valid until revoked. Also check session settings like IP restrictions or forced logout, as they can break integrations.
Another good practice is to use a dedicated integration user with proper permissions and longer session timeout to keep the connection stable.

If you are still facing issues, working with a salesforce crm consultant from Achieva.ai can really help. Their experts can review your OAuth setup, fix token handling, adjust security settings, and make sure your ServiceNow and Salesforce integration runs smoothly without repeated session failures.