Hi,
I am beginner in Postman. I have the following Post request body
{
“pageNumber”: 1,
“pageSize”: 10,
“sortParams”: [
{
“sortColumn”: “BranchCode”,
“sortOrder”: “Asc”
}
],
“filterParams”: {
“filterColumn”: “BranchCode”,
“FilterValue”: “MAA”,
“operator”: “eq”,
“logicOperator”: “and”,
“isCaseSensitive”: false,
“filterList”: null
}
}
The response is as follows
{
"pageNumber": 1,
"pageSize": 10,
"totalPages": 1,
"totalRecordsCount": 1,
"succeeded": true,
"message": null,
"errors": null,
"data": [
{
"branchId": 449,
"branchCode": "MAA",
"branchName": "TEST Chennai",
"branchCodeWithName": "MAA - TEST Chennai",
"companyId": 19,
"companyCode": "GIN",
"companyCompanyName": null,
"companyCompanyCodeWithName": null
} ]}
I am trying to get the request body and parse it and trying to validate it with reponse.
I wrote the following statements
let reqbody = pm.request.body
console.log(typeof reqbody) //returns object
let reqbody1 = pm.request.body.raw
console.log(typeof reqbody1) //returns string
when I try to parse either reqbody or reqbody1, I get the following error
JSONError: Unexpected token ’ ’ at 2:1"pageNumber": 1,
I tried replacing /trimming the spaces by using
myjson = reqbody.replace(/^\s+|\s+$/g, “”);
It says its not a function(type error)
Also pm.request.body.raw.sortParams returns undefined
I am really stuck as to what to do further. Can anyone please help me on how to get the request body or reading the complex sorting obj from request? Is this the right way of writing the script for this paticular usecase? Is there any other way to read the sorting obj from request and validate the sorting order of response?