Scripted Rest API Not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2022 06:18 AM
Hi All,
below is the script that i written on scripted rest api. but its not working when i send data like https://google.com/gtre
can any one help me on this
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var obj = {};
obj.number = request.pathParams.number;
obj.worknotes = request.pathParams.work_notes;
var gr = new GlideRecord("sc_req_item");
gr.addQuery("number", obj.number);
gr.query();
if (gr.next()) {
gr.work_notes = obj.worknotes;
gr.update();
response.setBody(obj);
}
})(request, response);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2022 07:56 AM
Please update the resource path etc
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2022 08:40 AM
Resource path: /api/396051/request/{number}/{work_notes}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 06:37 AM
Can you provide screenshots of your entire scripted REST API definition showing the REST Service definition (the one that you've named "request") and also the POST resource that you defined. If you don't have everything configured properly, it's easy to have a failure like you're seeing.
Frank
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 07:19 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-14-2022 07:42 AM
Hi,
1) clear the relative path since now the Method is POST; don't send anything in path parameters
2) you should be sending the JSON body like this in post body
{"number":"RITM0010236", "work_notes":"my testing"}
should be like this
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader