ServiceNow to Salesforce Integration using REST API and OAuth 2.0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
As a ServiceNow developer, I've always believed the platform's real power isn't just managing what happens inside it, it's how cleanly it can talk to everything outside it. So instead of building a one-off create a record and take a screenshot demo, I tried something closer to how real integrations actually get used: two independently triggered, real-time syncs from ServiceNow into Salesforce, both running on the same underlying architecture.
Introduction
What if creating a user in ServiceNow could automatically create the corresponding Account in Salesforce, and creating an Incident could automatically create a Case in Salesforce without anyone manually entering the same information twice?
This is where integration between ServiceNow and Salesforce becomes useful. Here, I will walk through a practical ServiceNow → Salesforce integration.
Overview
| Item | Value |
| Auth Flow | OAuth 2.0 Client Credentials |
| Salesforce Object Accessed | Case |
| Direction | ServiceNow -> Salesforce (Outbound REST) |
| Salesforce App Type | External Client App |
Salesforce Setup : Create an External Client App
Go to: Setup → App Manager → External Client Apps → External Client App Manager → New External Client App
- Name the app and enable OAuth settings.
- Under OAuth Scopes, select permissions like Full access or API access.
Note : Salesforce will generate a Client ID and Client Secret, which we will use to authenticate ServiceNow.🔑
ServiceNow Setup :
1. Application Registry (OAuth Provider) :
System OAuth → Application Registries → New → Connect to a third party OAuth Provider
| Field | Value |
| Name | e.g. Salesforce OAuth 2.0 |
| Client ID | Consumer Key from Salesforce |
| Client Secret | Consumer Secret from Salesforce |
| Grant type | Client Credentials |
| Token URL | https://<your-domain>/services/oauth2/token |
| Authorization URL | https://<your-domain>/services/oauth2/authorize |
| Active | ✔️ |
2. REST Message :
System Web Services → REST Message → New
| Field | Value |
| Name | e.g. Salesforce Case Integration |
| Endpoint | https://<salesforce-instance>/services/data/v58.0/sobjects/Case |
| Authentication type | OAuth 2.0 |
| OAuth profile | <created_above> |
Implementing Business Rule for dynamic creation :
- Create a Business Rule in ServiceNow that triggers on Incident creation.
- Call the Outbound REST Message in the Business Rule to send the incident data to Salesforce and create the case.
- Capture the Case ID from the response and update the Incident record with this ID.
Script :
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
try {
var r = new sn_ws.RESTMessageV2('Salesforce Case Integration', 'POST');
r.setStringParameterNoEscape('description', current.description);
r.setStringParameterNoEscape('short_description', current.short_description);
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);
//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');
//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
} catch (ex) {
var message = ex.message;
}
})(current, previous);
Testing the Integration :
- Create an incident in ServiceNow.
- The Business Rule will trigger, calling the REST Message to Salesforce.
- Same way create an User in ServiceNow.
- In Salesforce respective acoount will be created.
Conclusion
Finally you've successfully integrated ServiceNow with Salesforce using REST API and OAuth 2.0. One of the most valuable parts of this exercise was understanding how ServiceNow can communicate with external platforms securely through REST APIs and OAuth, rather than just working within the ServiceNow platform.
Also Refer the Official Docs for detailed understanding :
Integrating with Salesforce CRM
If you have any questions, feel free to reach out in the comments!
