0

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

lpizzinidev
  • 12,741
  • 2
  • 10
  • 29

1 Answers1

0
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}}

PDHide
  • 18,113
  • 2
  • 31
  • 46
  • Hi, thank you for quick feedback. Yesterday I found solution and I think that it is very simililar to your proposal. I am newbee in this. I will try to check your propposal because it is looks more than mine solution :) bodyData = JSON.parse(responseBody) IRS1occupation = bodyData.occupation console.log(IRS1occupation) pm.environment.set("IRS1occupied", IRS1occupation); – Jozef Michališín Feb 11 '21 at 07:50
  • you don't have to parse the response you can directly use pm.response.json() both does the same thing , this is cleaner – PDHide Feb 11 '21 at 07:57
  • Could you accept the answer by clicking the tick sign near to the answer – PDHide Feb 11 '21 at 07:58
  • 1
    I did acording you proposal... looks much better :) pm.environment.set("IRS2occupied", pm.response.json().occupation); console.log(IRS2occupation) – Jozef Michališín Feb 11 '21 at 08:50