Reputation: 59605
In one request I have the following:
var data = JSON.parse(responseBody)
postman.setGlobalVariable("myData", data.myData)
I'm looking to include this myData
in the request body for another request.
The body for that request looks something like this:
{
"myData": "{{myData}}"
}
However this does not work. The global is set to [object Object]
and that string gets sent to the server in the request body instead of the actual object.
Is there a way to attach this globals[myData]
object to the request body in Pre-request Script
? Something like the following?
requestBody.myData = globals[myData]
Upvotes: 0
Views: 3083
Reputation: 710
Two things should fix this for you:
{{myData}}
variable in your post bodymyData
variableIt should look like this in your test:
postman.setGlobalVariable("myData", JSON.stringify(data.myData))
And this in your body
{
"myData": {{myData}}
}
Upvotes: 2