Scripted Rest API Not working

rambabu1
Giga Expert

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);

 

 

11 REPLIES 11

Please update the resource path etc

 

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Resource path: /api/396051/request/{number}/{work_notes}

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

Hi Frank,

Please see the below screenshot.

find_real_file.png

USing Explore REST API i am testing whether data populated correctly or not (if  provided data is URL in that case i am receiving error message.)

find_real_file.png

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

find_real_file.png

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader