Hi All, spaces and dots are not taking in request body in scripted rest api
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2024 07:02 AM - edited ‎02-11-2024 07:13 AM
Hi All, in one of my json payload there is a field with the value as "test application", while i am trying to retrieve the data i am only getting the first name that is only test from this value test application. However i am able to create a record in my table but the problem is the record gets created with the name a only test not test application. How to avoid these spaces issues? Help me here
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2024 10:59 AM
Hi @Venkatesh098765 ,
You should use
JSON.stringify(JSON.parse(body)
//body is your object variable.
Example:
var body = ' { "name": "test", "description": "test json", "website": "domain.com" } ';
JSON.stringify(JSON.parse(body)
Result:{"name":"test","description":"test json","website":"domain.com"}
Thanks,
Pratik Malviya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2024 10:03 PM
Hi Pratik,
Thanks for the response.Like I am using this way:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-11-2024 11:18 PM - edited ‎02-11-2024 11:29 PM
Hi @Venkatesh098765 ,
Convert it to string and try to print
var reqbody = request.body.dataString;
var parsedBody = JSON.parse(reqbody);
var app_id = parsedBody.application_id.toString();
var app_name = parsedBody.application_name.toString();
var grp_id = parsedBody.group_id.toString();
var grp_name = parsedBody.group_name.toString();
var typrofoperation = parsedBody.typrofoperation.toString();
Below i tried in PDI BG its working
var reqbody = {
"application_id": "12",
"application_name": "App name3",
"group_id": "123",
"group_name": "group name3",
"typrofoperation": "group.application_assignment.add"
};
var parsedBody = reqbody;
var app_id = reqbody.application_name.toString();
gs.log("app_id: " + app_id);
Mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-12-2024 12:09 AM
Hi Anand,
Thanks for the response. When I am trying this and trying to hit the api and print the data an error was frequently occuring seems like OOB error.please find the error here