I am data driving a test using a JSON source file. Instead of replacing single variables at run time, is it possible to replace the entire request body with the one from the data file?
So, for example, if my data looked like the screenshot below, could I use the ‘message’ object as the entire request body?
I followed this tutorial, but was still getting [object Object] in the Request Body when running my test through the collection runner (now am getting ‘Data unavailable’, which I’ve opened another question about).
This is what I have:
Request Body: {{guest}}
Pre-request script:
let newGuest = pm.iterationData.get('guest');
if (pm.iterationData.has('guest')) {
console.log(JSON.stringify(newGuest)) // successfully prints out what's expected
pm.environment.set('guest', JSON.stringify(newGuest)); // doesn't set variable properly
}
printing pm.environment.get('guest') prints what I would expect
As there are now 2 variables at different scopes (data and environment), with the same name, these might be clashing.
Try changing the name of the environment variable from ‘guest’ to ‘newGuest’ and the value in the request body to {{newGuest}}. Ensure to save the request before running this in the Collection Runner.
These names are just suggestions, you can call it whatever you like