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

Scripted Rest api for incident create

Ketan Pandey
Tera Expert

I am working a requirement where i want to create a incident and incident task when an request(JSON) received ,

Please suggest  

8 REPLIES 8

Hi Amit,

 

Thank you for your response.

Here in my case ,External system will make the REST call

Hi @Ketan Pandey 

 

Thank you for the clarification. You can make use of ServiceNow Table REST API to create incident and incident task. Please refer below link for creating incident using REST API explorer.

https://docs.servicenow.com/bundle/tokyo-application-development/page/integrate/inbound-rest/task/t_...

 

For creating Incident task, make use of Table API only in REST API explorer on the table "incident_task". Please refer below snip. Here, in the incident, pass the value of the sys_id of the incident created in the previous REST API call.

 

AmitVerma_0-1705574625214.png

 

AmitVerma_1-1705574642411.png

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Ketan Pandey 

 

https://youtu.be/xRqIr5YwAFs

 

My video will help you.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************
csa #ServiceNow #TechnoFuncational Disclaimer: These videos are from my training batch. These videos did not promote any ServiceNow Sales pitch or marketing. These videos are only for knowledge purposes & basic on my experience & Knowledge. Redistribution or copying of functionality is not ...

sumanta pal
Kilo Guru

As a ServiceNow expert, I can tell you that ServiceNow can both send and receive RESTful API calls. However, the structure of the JSON response or request is not predefined and depends on the specific API endpoint and the data being sent or requested.

Here are the steps to set up a RESTful API in ServiceNow:

1. Navigate to System Web Services > Outbound > REST Message.
2. Click New to create a new REST message.
3. Fill in the fields, such as Name, Endpoint, HTTP Method, etc.
4. You can add parameters to the HTTP request in the HTTP Request tab.
5. You can also add or modify the HTTP headers in the HTTP Headers tab.
6. In the content tab, you can define the body of the request. If you're sending a JSON payload, you can define it here.
7. Once you've set up the REST message, you can use the 'Test' related link to send a test request.

Here's a sample script to send a RESTful API call from ServiceNow:

javascript
var restMessage = new sn_ws.RESTMessageV2('YOUR_REST_MESSAGE', 'DEFAULT_HTTP_METHOD');
restMessage.setStringParameterNoEscape('parameter1', 'value1');
restMessage.setStringParameterNoEscape('parameter2', 'value2');
var response = restMessage.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();


To receive a RESTful API call in ServiceNow, you need to create a Scripted REST API. Here are the steps:

1. Navigate to System Web Services > Inbound > Scripted REST APIs.
2. Click New to create a new Scripted REST API.
3. Fill in the fields, such as Name, API ID, etc.
4. Click Submit to create the API.
5. Now you can add resources to the API. Each resource corresponds to a specific URL and HTTP method.
6. For each resource, you can define a script to process the request and send a response.

Here's a sample script to process a RESTful API call in ServiceNow:

javascript
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var body = request.body.data;
var parameter1 = body.parameter1;
var parameter2 = body.parameter2;
// process the parameters and perform some action
response.setStatus(200);
response.setBody({
result: 'Success'
});
})(request, response);


Remember to replace 'YOUR_REST_MESSAGE', 'DEFAULT_HTTP_METHOD', 'parameter1', 'value1', 'parameter2', 'value2' with your actual REST message name, HTTP method, and parameters.

For asking ServiceNow-related questions try this :

For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.

Please visit : https://nowkb.com/home
Our Website :https://nowkb.com/home