How to update environment variables based on a response in Postman

Written by ppolyzos

Software engineer based in Athens, Greece


  1. chenna

    How do you select 001-0000084765 from below JSon response.

    Tried this code but doesn’t work

    var jsonData = JSON.parse(responseBody);

    1. ppolyzos

      To access hierarchyId you can do the following:

      One thing that might help you is Postman console. You can open it from View -> Show Postman Console and then you use console.log to help you. More info here

  2. Jhuang

    how to parse an xml response:


    I tried this and it did not like the last
    var jsonData = xml2Json(responseBody);
    var response = JSON.parse(jsonData);


    1. ppolyzos

      To view the output of your jsonData variable you can use Postman Console. Open it from View -> Show Postman Console and then you use console.log to help you.
      Usually the parsing is a little different than you might expect, but with Console you ‘ll figure out the problem easily.

  3. niti

    How to get “Qk4oSI” from the response:

  4. Cain

    How would I get BackCustomerID? I’ve tried:

    1. ppolyzos

      You response is an array, so you need to get the first element:

    1. ppolyzos

      You can include those conditions in your Tests script.

  5. kanna

    “serial”: “123456”,
    “headers”: {
    “Authorization”: “Signature keys=\”/smarId/hello/1234.123445\”,signature=\”””

    I want only */smarId/hello/1234.123445* as environment variable

    1. ppolyzos

      If only the Signature keys change, then you can do the following:

      You can learn more about string interpolation and template literals in this link

    1. ppolyzos

      Let’s assume you have this request from OpenWeather API:

      To access the ETag value you can use the following code in Tests panel:

      For more info on postman’s response API you can have a look here

  6. Udhaya

    Hi I am new to postman, can we write JSON object in pre-req?
    and use this in the body?

    1. ppolyzos

      In order to that one way would be to do the following:

      Step 1: Stringify your object and assign it to an environment variable in Pre-request Script tab:

      Step 2: In Body use that variable in your object:

      Note the {{}} which are used in order to use this variable.

      postman set object in request body through environment variable

Leave a Comment

Your email address will not be published. Required fields are marked *