The CreatorCon Call for Content is officially open! Get started here.

Selva Arun
Mega Sage
Mega Sage

🚀 Integrating ServiceNow with Salesforce using REST API and OAuth 2.0

🌟 Are you working with both ServiceNow and Salesforce? Integrating these two platforms can streamline your processes and boost efficiency. Here's a step-by-step guide to help you integrate ServiceNow with Salesforce using REST API and OAuth 2.0 authentication. 💼

 

🔍 1. Understanding the Integration Flow

Before diving into the technical steps, let’s quickly take a look at the flow diagram. The process begins when an incident is created in ServiceNow, triggering a call to Salesforce using REST API and OAuth 2.0 authentication. Once authenticated, ServiceNow sends a POST request to Salesforce to create a case. Salesforce responds with a Case ID, which is then updated back into the ServiceNow incident record. This ensures both systems stay in sync, with accurate updates. 🔄

SelvaArun_2-1740003768484.png

 

 

SelvaArun_1-1740003731909.jpeg

 

🔧 2. Creating a Connected App in Salesforce

Create a Connected App in Salesforce to allow authentication via OAuth 2.0:

  1. Navigate to Setup in Salesforce.
  2. In the search bar, type “App Manager”.
  3. Click on App Manager, then New Connected App.
  4. Name the app and enable OAuth settings.
  5. Under OAuth Scopes, select permissions like Full access or API access.

 

Salesforce will generate a Client ID and Client Secret, which we will use to authenticate ServiceNow. 🔑

🔒 3. Setting Up OAuth in ServiceNow

Set up OAuth 2.0 authentication in ServiceNow:

  1. Go to Application Registry in ServiceNow.
  2. Click New, then select Connect to an OAuth Provider.
  3. Choose Salesforce from the list of providers or create a custom one.
  4. Enter the Client ID and Client Secret from the Salesforce Connected App.
  5. Set the OAuth endpoint for Salesforce, typically https://login.salesforce.com/services/oauth2/token

SelvaArun_3-1740003810390.jpeg

🌐 4. Creating an Outbound REST Message in ServiceNow

Create an Outbound REST Message in ServiceNow to send the POST request to Salesforce when an incident is created:

  1. Navigate to Outbound REST Messages in ServiceNow.
  2. Create a new REST Message and provide the Salesforce API endpoint for creating a case (e.g., https://your_instance.salesforce.com/services/data/vXX.0/sobjects/Case/).
  3. Under HTTP Methods, select POST.
  4. Add necessary headers, including the Accept: application/json and the Content-Type as application/json.
  5. Add the data you want to send in the Body section, like the incident’s description, priority, and status.

SelvaArun_4-1740003874269.jpeg

SelvaArun_5-1740003913561.jpeg

 

 

🧪 5. Testing the Outbound REST Message and get the OAuth Token

Test the Outbound REST Message to ensure everything works correctly:

  1. Go to the REST Message you created and get the OAuth Token by clicking on Get OAuth Token button by entering the Salesforce username and password and click Test.
  2. If everything is set up correctly, you should receive a success response from Salesforce, including the Case ID.

SelvaArun_6-1740004037523.jpegSelvaArun_7-1740004052725.jpeg

 

 

🛠️ 6. Automating with a Business Rule

Automate the process so that a case is automatically created when an incident is created in ServiceNow:

  1. Create a Business Rule in ServiceNow that triggers on Incident creation.
  2. Call the Outbound REST Message in the Business Rule to send the incident data to Salesforce and create the case.
  3. Capture the Case ID from the response and update the Incident record with this ID.

SelvaArun_9-1740004115013.png

 

SelvaArun_8-1740004084547.jpeg

(function executeRule(current, previous /*null when async*/) {
 
try {
 var r = new sn_ws.RESTMessageV2('Salesforce Integration 2.0', 'Create Case');
 r.setStringParameterNoEscape('description', current.description );
 r.setStringParameterNoEscape('test_case', current.short_description);
 r.setStringParameterNoEscape('status', 'New');
 r.setStringParameterNoEscape('priority', current.priority);
 
 // Execute the REST message and get the response
        var response = r.execute();
        var responseBody = response.getBody();
        gs.log(responseBody);
        var httpStatus = response.getStatusCode();
        gs.log(httpStatus);
        // Check the response and handle accordingly
        if (httpStatus == 201) {
            // Parse the response to get the created task ID
            var responseObj = JSON.parse(responseBody);
            var caseID= responseObj.id;
            current.correlation_id = caseID;
            gs.addInfoMessage('the case id:'+ caseID);
            current.update(); // Store the created task ID in the incident record
           
            // Optionally log or handle success
            gs.info('Task created successfully in Salesforce. Task ID: ' + responseObj.id);
        } else {
            // Handle any non-successful responses
            gs.error('Failed to create task in Salesforce Status Code: ' + httpStatus);
        }
       
    } catch(ex) {
        // Handle any errors in the try block
        gs.error('Error occurred while creating task in Azure DevOps: ' + ex.message);
    }
})(current, previous);

7. Testing the Integration

Test the integration:

  1. Create an incident in ServiceNow.
  2. The Business Rule will trigger, calling the REST Message to Salesforce.
  3. Salesforce will create a case and return the Case ID.
  4. The incident record in ServiceNow will be updated with the Salesforce Case ID in the Correlation ID field.

SelvaArun_10-1740004151528.png

 

🎉 Conclusion

By following these steps, you've successfully integrated ServiceNow with Salesforce using REST API and OAuth 2.0. This integration helps ensure incidents in ServiceNow are automatically converted to cases in Salesforce, reducing manual work and improving efficiency. 🔗

 

For more details, check out the API documentation linked below. If you have any questions, feel free to reach out in the comments!

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_sobject_create.htm

 

Also, please check out my YouTube channel for a detailed walkthrough of this integration process:

 

https://www.youtube.com/watch?v=zm2R2avtezQ

 

If you believe the solution provided has adequately addressed your query, could you please **mark it as 'Helpful'**.  This will help other community members who might have the same question find the answer more easily.

 

Thank you for your consideration.

 Selva Arun

 

Comments
pramod9
Tera Contributor

This was really helpful, can you please also create artical/video for inbound part.

When case is created in salesforce how to trigger incident/request(item) in servicenow using salesforce spoke.

Selva Arun
Mega Sage
Mega Sage

@pramod9,

Sure, Pramod!! I will and thank you so much for finding it useful.

 

Regards,

 

Selva

Reina Fujita
Tera Contributor

"I believe the request was exactly what I want to achieve in my current project: 'When a case is created in Salesforce, how to trigger an incident/request (item) in ServiceNow using Salesforce Spoke.'

Do you have any videos demonstrating how to implement this? I'd appreciate it if you could share them with me!"

Alan42
Tera Guru

Worked great.  Thank you.   When getting the token we encountered some issues.    We received a general authorization error  which was fixed by adding an authorization URL even though it isn't required.    Then we got the error 'error=redirect_uri_mismatch&error_description=redirect_uri%20must%20match%20configuration' which required us to change the redirect URL to the base URL we used when creating the client ID and secret.   After that we were able authenticate.        

Version history
Last update:
‎02-19-2025 02:36 PM
Updated by:
Contributors