REST API POST method

amit_kishore
Tera Contributor

HI All,

 

I am looking for a POST REST API query for an incident table for ebond in such a way which will return with response with 2 fields values (Incident no/correlation id  ) when we send request for new incident creation to other system with 10 fields 

4 REPLIES 4

Eshwar Reddy
Kilo Sage

Hi @amit_kishore 
You can create a Scripted REST API to address your scenario.


// Parse request body

var requestBody = request.body.data;

// Create a new GlideRecord for the Incident table

var gr = new GlideRecord('incident');

gr.initialize();

gr.short_description = requestBody.short_description;

gr.description = requestBody.description;


gr.insert();

var incidentNumber = gr.number;

var correlationId = gr.sys_id;

var responseObj = { "incident_number": incidentNumber,"correlation_id": correlationId }; // Send response response.setContentType('application/json');

response.setStatus(201);

// HTTP status code for Created

response.setBody(JSON.stringify(responseObj));


Thanks,

Eshwar

 

Please mark this response as Correct and Helpful if it helps you can mark more that one reply as accepted solution

we can do with Scripted API which is easier way however the side team is using import set APi mentioned. hence, we are using the same 
kindly let us know if this can done with Import set API

Based on my understanding, it's not possible to directly customize the response from the Import Set API to meet specific requirements. Instead, you have a few alternatives:

  1. Scripted REST API: Create a scripted REST API for more flexible and customized responses.
  2. External Processing: Use a REST API to send the required values, and once the incident is created in ServiceNow or You will receive the `sys_id` in the response. You can then use the `GET` method to retrieve the incident's field values.

KevinBellardine
Kilo Sage

The problem you're going to have is that the Import Set API isn't actually creating a record in the incident table. It's creating a record in the targeted import set table, and the transform on that table is what ultimately creates the record. If you're trying to do this without using a scripted rest API then it would probably be better to have the other side reach back out to you with a different API (maybe Table?) once the Incident is created. They could even do this in the transform script itself.