I am trying to run thses apis and the data in the apis are in the format
{
"condition":{
"scenario": "success",
"api": "/api/rest/2.0/users/create"
},
"data":{
"name": "abcdef",
"display_name": "abcdef_abcdef",
"password": "Abcd@2023",
"email": "abcde@gmail.com"
}
}
similar to this
This is the image of the pre-request script
This is the pre-request script to check condition.
The error I am getting is
These are the apis Iβm trying to run from runner
There are two ways to accessing data from JSON or CSV files.
Postman JavaScript reference | using-data-variables-in-scripts
Using CSV and JSON Data Files in the Postman Collection Runner | Postman Blog
It looks like you are converting what is already an object, so Iβm not sure toObject is needed.
The error is saying its reading the variable as [object Object] instead of the first character being a { like its meant to be. Therefore the error is correct. The βoβ is unexpected and the wrong type.
I prefer method two which is to access the elements using the special βdataβ dictionary.
data.condition.api or data[βconditionβ][βapiβ]
If you console log data on its own as the first line in your pre-request script, it should already be an object that you can work with.
// try it yourself
console.log(data);