I have saved my request as object by doing:
pm.environment.set(“Create Draft”, pm.request)
now I have to reuse it in a pre request script :
But first I need to update variable in body of this request which is a global variable and already updated by earlier request this is still using old value when this request was saved.
Welcome to the community
Trying to get better clarification on what you’re facing.
One thing to keep in mind, if you are planning to save an entire request you may need to stringify it first before you put it into an environment variable.
Check out this blog to learn more : When and How to Use JSON Serialization in Postman | Postman Blog
Ideally you will want to use stringify to set your env variable :
Now in the pre-request script you will have to parse that json to get the env variable to send :
var Obj = JSON.parse(pm.environment.get("var-CreateDraft"));
you can take a look at how some of these requests are used in this example collection :
^ Take a look at folder Using pm.sendRequest to learn more
Hi @pooja-mistry thanks for reply.
In one of my request test I am using this “pm.environment.set(“Create Draft”, pm.request)” to save the request, and its saving in my enviroment variable as “[object Object]”
In another request pre request script I am using a same type of saved request and updating a variable, but this updated value of variable is not being used by above request when I am using that request in pre request script. Its using the value when that request is saved.
All the request are going in correct order but as I mentioned its not taking updated variable value. I am not sure what I want to do is correct?
I can directly create new request instead of using pre-request script, that will work easily.