postmanpostman-testcase

How to use object in postman params?


I got a response from a get request as an object and added it to an environment variable. now I want to use it in another request params but I don't know how to do it.


Solution

  • You should use JSON stringfy in order to save in the environment. after that use the Pre-request Script in order to add query params and JSON parse to get data from the environment. follow these steps as a sample code.

    1- pm.environment.set("key", JSON.stringfy(object))
    2- go to Pre-request Script
    3- var data = JSON.parse(pm.environment.get("key"))
    4- pm.request.url.addQueryParams([`param=${data.child}`])