Is it possible to POST/PUT a request from ServiceNow to third party API? If it is possible, what is the process?

Vijay101
Kilo Contributor

POST/PUT request from ServiceNow to third party REST API.

1 ACCEPTED SOLUTION

Hello Vijay,

Thanks for the details.

Please try the below solution and let me know if it works for you.

Step 1. Create a New Rest Message under System Web Services -> Outbound -> Rest Message -> New.

Name: ServiceNow

Endpoint: https://{your-instance-here}.service-now.com/api/now/table/ (We are using the Table API here).

Authentication: Basic 

Basic Auth profile: This consists of the username and password that will be used to authenticate the instance. You can create a new profile or use the existing one. Please note you are providing the user that has the privileges or permissions for integration.

Save the Rest Message. 

find_real_file.png

Step 2: After saving the Rest Message. You will find the HTTP Methods section. 

Click on New. We will now create an HTTP method to inactive the user in another ServiceNow instance.

Name: Inactive User

Http Method: PUT

Endpoint: https://{your-instance-here}.service-now.com/api/now/table/sys_user/${sysid} 

*Note: ${sysid} is the sys_id of the user record you want to update. We will be creating a variable for this in the next steps.

Authentication: Inherit from Parent

HTTP Request: 

       HTTP Headers: 

           - Content-Type: application/json

       Content: 

              {
                   "active":"false"
              }

Click on Save

find_real_file.png

Step 3: Create a new Variable Substitutions

Name: sysid

Escape type: No escaping

Update the Request.

find_real_file.png

 

Step 4: We now need to create a Business Rule on sys_user table

Go to User Administration -> Users -> Configure -> Create New Business Rule

Name: SN_Inactive User

Table: User[sys_user]

When to Run:

     When: after Update

     Filter Condition: Active is false

Advance -> Script:

(function executeRule(current, previous /*null when async*/ ) {

     try {
             var r = new sn_ws.RESTMessageV2('ServiceNow', 'Inactive User');
             r.setStringParameterNoEscape('sysid', current.sys_id);

                var response = r.execute();
                var responseBody = response.getBody();
                var httpStatus = response.getStatusCode();
          } catch (ex) {
                var message = ex.message;
         }

})(current, previous);

 

Save the business rule.

The user in instance 2 will be set to inactive once the user in instance1 is set to inactive. 

Please let me know if this works for you.

 

Thanks,

Shweta

View solution in original post

4 REPLIES 4

Nick Rosenstiel
Tera Contributor

Since you are doing a post/put I'll take it you're not importing data so will skip the REST API as a Data Source. You can either script the post/put completely in a Script Include or use ServiceNow's Flow Designer. For a Script Include I recommend reading up on the SN Product Documentation  here. For Flow Designer, if you create a new Action, there a "REST" action step that can make a REST API call with a bunch of pre-defined configurations. (There is a third, if you like powershell you can make your Rest calls in powershell and place that on the Mid Server and use the "PowerShell step"). My personal recommendation would be to use Flow because then you can include your calls in SubFlows/Flows, there is a JSON Parser as well as a XML Parser steps to make data extraction very easy. 

 

Example of Script Include:

find_real_file.png

Example of REST Action Step: 

find_real_file.png

There is also some System Web Services module: 

find_real_file.png

This I haven't explored as much but might be a good place to start. I also recommend reading up on the Web Service documentation to see if there is anything of interest to you there: https://docs.servicenow.com/bundle/paris-application-development/page/integrate/web-services/reference/r_AvailableWebServices.html

Shweta Kadam1
Tera Expert

Hello Vijay,

Yes, It is possible to POST/PUT a request from ServiceNow. This can be done from the Rest Message under Outbound-> Rest Message. You would need to create a new Rest Message record providing the details like Name, Endpoints, Authentication Type, HTTP Request, etc.

I would request you to provide more details of your use case, to be able to help you. Meanwhile, you can go through my article created for a ServiceNow JIRA Integration

 

Thank you,

Shweta

Thank you for the Info. The scenario is:

Step_1. A ServiceNow Request is created to set a user to become inactive on a future date. (Probably this can be done in a workflow and trigger a timer and set active flag to false in a user on a future date)

Step_2. Once the user is Inactive in ServiceNow, send a Outbound Rest API call to third party API ( .NET core web api, with JWT token authentication, and post the user
record(json format), using the ServiceNow post record, set that user active flag to false in another system).

Step_2 should immediately trigger after the user active flag is set to false in Step_1.

Hello Vijay,

Thanks for the details.

Please try the below solution and let me know if it works for you.

Step 1. Create a New Rest Message under System Web Services -> Outbound -> Rest Message -> New.

Name: ServiceNow

Endpoint: https://{your-instance-here}.service-now.com/api/now/table/ (We are using the Table API here).

Authentication: Basic 

Basic Auth profile: This consists of the username and password that will be used to authenticate the instance. You can create a new profile or use the existing one. Please note you are providing the user that has the privileges or permissions for integration.

Save the Rest Message. 

find_real_file.png

Step 2: After saving the Rest Message. You will find the HTTP Methods section. 

Click on New. We will now create an HTTP method to inactive the user in another ServiceNow instance.

Name: Inactive User

Http Method: PUT

Endpoint: https://{your-instance-here}.service-now.com/api/now/table/sys_user/${sysid} 

*Note: ${sysid} is the sys_id of the user record you want to update. We will be creating a variable for this in the next steps.

Authentication: Inherit from Parent

HTTP Request: 

       HTTP Headers: 

           - Content-Type: application/json

       Content: 

              {
                   "active":"false"
              }

Click on Save

find_real_file.png

Step 3: Create a new Variable Substitutions

Name: sysid

Escape type: No escaping

Update the Request.

find_real_file.png

 

Step 4: We now need to create a Business Rule on sys_user table

Go to User Administration -> Users -> Configure -> Create New Business Rule

Name: SN_Inactive User

Table: User[sys_user]

When to Run:

     When: after Update

     Filter Condition: Active is false

Advance -> Script:

(function executeRule(current, previous /*null when async*/ ) {

     try {
             var r = new sn_ws.RESTMessageV2('ServiceNow', 'Inactive User');
             r.setStringParameterNoEscape('sysid', current.sys_id);

                var response = r.execute();
                var responseBody = response.getBody();
                var httpStatus = response.getStatusCode();
          } catch (ex) {
                var message = ex.message;
         }

})(current, previous);

 

Save the business rule.

The user in instance 2 will be set to inactive once the user in instance1 is set to inactive. 

Please let me know if this works for you.

 

Thanks,

Shweta