samedi 6 novembre 2021

Setting Postman env variable based on the repsonse where certain criteria is met

When I get a response in Postman, I want to be able to set an environment variable (using

pm.environment.set("variable_key", "variable_value");

when a condition is met from the response array.

So the requirements:

  • set an environment variable named idForAbc to the value of someArray.id where someArray.criteria = "ABC" (so idForAbc = 1)

  • set an environment variable named idForXyz to the value of someArray.id where someArray.criteria = "XYZ" (so idForXyz = 2)

Here is my sample response:

Example Response

Aucun commentaire:

Enregistrer un commentaire