I am doing body level encryption in the pre-request script and want to the replace the entire reuqest body with encrypted data before sending the actual request
Hey @docking-module-geol4,
Welcome to the community
Is there anything, a question, or probably a hint as to where you’re trying to drive this discussion? Are you facing any issues with the pre-request script? We have some wonderful folks in the community who can help but make sure you mention what it is that you’re looking for.
just provide a variable in place of request body:
{{requestBody}}
And modify this from pre-request script
pm.variable.set("requestBody", JSON.stringify( { "name":"test"} ))
you can also modify it as
pm.request.body='{"name":"age"}'
Let us if you would need any help
I tried this and it didn’t work, instead this works
pm.request.body.raw = { name: “age” }
I want to append some items in the request body.
I tried this but not working
How did you try this?
Can you provide a screenshot?
The above examples are replacing the body.
If you want to append, you can do it using the following method.
const body = JSON.parse(pm.request.body.raw); // retrieve current body
// update the body\object as appropriate
pm.request.body.raw = body; // write back updated body