REST API POST method
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2024 08:45 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2024 09:22 AM - edited 09-09-2024 09:23 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2024 12:32 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2024 10:32 PM
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:
- Scripted REST API: Create a scripted REST API for more flexible and customized responses.
- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2024 07:22 AM - edited 09-10-2024 07:23 AM
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.