- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2017 01:08 AM
Hello,
So I'm testing out my new Scripted REST API Code which should pretty much return the body parameters. The parameter that I'm passing has a name of short_description and it's is Short Description Sample.
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var sampleBody = request.body;
var sampleEntry = sampleBody.nextEntry();
var desc = sampleEntry.short_description;
return {
"short-description" : desc
};
})(request, response);
Unfortunately, after running the message, an error output came out
{
"error": {
"detail": "",
"message": "com.glide.rest.domain.ServiceException: Exception while reading request"
},
"status": "failure"
}
I tried looking for a fix and checked the best practice in making my function work but it seems that I'm already following it based on this ServiceNow documentation for Scripted REST API:
RESTAPIRequestBody - nextEntry()
Is there any other fix that you guys can recommend that I use to return the parameter? If so, what is it and thanks for your help in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2017 01:32 AM
Hi Raymund,
The allowed content- types are application/json, application/xmls for ServiceNow REST services. multipart/form-data is not allowed.
Just switch your postman settings from form-data to raw and paste json equivalent of your request, then it should work.
{
"short_description" : "test",
"test" : "test2"
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 04:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2022 01:05 AM
I had a similar message, i had application/json and i had raw but my issue was that i had a rogue apostrophe which meant i didn't have valid JSON. If you've double checked you're JSON and it looks correct, maybe copy and paste it into a JSON checker.
Hope this helps!