- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2017 05:29 AM
Hello Everone,
I want to create a record using Scripted Rest Api.
Here is my code:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var gr=new GlideRecord('sn_customerservice_case');
gr.initialize();
gr.description="Testing going on"
gr.impact="4";
var abc=gr.insert();
return "Sys id is "+abc;
})(request, response);
When I am inserting a its showing this error from POSTMAN
Error:
{
"error": {
"detail": "",
"message": "java.lang.IllegalArgumentException: Cannod decode: java.io.StringReader@1142887"
},
"status": "failure"
}
Solved! Go to Solution.
- Labels:
-
Benchmarks
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2017 07:56 AM
Hi Rahul,
In postman add the content body in the body part and select raw as the format then you should get an area to put the json request body and add the body there and hit the endpoint
format in your earlier screenshot is form-data make it to raw
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2017 06:18 AM
Hi Rahul,
So you are using post method. Are you sending the request body as well in the postman when calling this api endpoint.
Can you share screenshot of the postman tool.
Also you are not sending the response in correct format.
Correct format is:
var responseBody = {};
responseBody.sysId= abc;
responseBody.status = "Success";
response.setBody(responseBody);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2017 06:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2017 06:39 AM
Hi Rahul,
You need to send the body as json key value pair and fetch the body content in the scripted rest api and then parse the request body, insert record and return response.
following post which I commented on should help you:
https://community.servicenow.com/thread/276281
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-09-2017 07:04 AM
Hi Ankur,
This is the code that I have written on the Scripted Rest. I checked in the log and I am able to retreive desc value. But I am not able to understand why this error is coming for the Postman as if i try from Rest Api Explorer I am able to insert the data
And this is Response that I am getting
I tried to hit this Api with the Soap UI and I am able to insert the data.
But I am not able to insert to data from Postman and I have to show demo to my client from Postman only.