- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2022 06:58 AM
Scenario: I need to print one of the attribute value from JSON payload from 'Query parameter' to response body.
Example: In the payload it is given:
"site": {
"name":"abc demo"
}
So in this case i need to print the name value that is 'abc demo' in response body.
Issue: I wrote code but it is giving below error:
"message": "Cannot read property \"name\" from undefined",
Script:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var requestbodydata = request.queryParams.input[0];
var test = requestbodydata .site.name;
return(test);
}
Any idea how to solve this?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2022 07:13 AM
Do one thing:
var requestbodydata = JSON.parse(request.queryParams.input[0]);
return requestbodydata.site.name;
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2022 07:06 AM
Hey,
You have a spcae:
var test = requestbodydata .site.name; remove this, it should work
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2022 07:10 AM
Hi Aman.
In the actual script there is no space.
Regards,
Vishal

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2022 07:13 AM
Do one thing:
var requestbodydata = JSON.parse(request.queryParams.input[0]);
return requestbodydata.site.name;
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2022 07:20 AM
getting error:
"error": {
"message": "Expected end of stream at char 6",