Warm tip: This article is reproduced from serverfault.com, please click

Conditioned next post cmd according to response variable

发布于 2021-02-10 14:15:38

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

Questioner
Jozef Michališín
Viewed
0
PDHide 2021-02-11 03:10:03
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}}