jsonpostmanplcpostman-pre-request-scriptpostman-mocks

Conditioned next post cmd according to response variable


with get, I am trying to get location status from the machine by CMDs from the postman. I am sending commands for transport to defined locations. These locations have some status. This status I can get by:

http://localhost:9999/services/iag/logimat/A1/location/LOC_R-033

Response:

{
    "id": {
        "locId": "LOC_R-033",
        "logimatId": "A1"
    },
    "locked": "none",
    "type": {
        "typeId": "irrigation",
        "height": 375,
        "counter": 0
    },
    "occupation": true,
    "tray": "23344435001"
}

I don't know how to get the occupation value flag from the response. Is it possible via postman? I wanted to use it as a variable that will be used as a condition for the next request. Thank you


Solution

  • pm.environment.set("value",pm.response.json().occupation)
    

    you can get the json response in script section as pm.response.json()

    from this call the occupation as its a direct property of that json object.

    THen use pm..set , in my example i used environment

    you can access this value as

    pm.environment.get("value")  in script section (pre-request and test)
    

    and every other sections you can access it as {{value}}