Extract request variable

Hi ,
I need to get the value from the request sent and verify it against the response. So, I need to write the test in that I need to extract the value from the body of the request and compare it with the response variable. The body of the request contains some environment variables as well but this particular field that I need to extract the value is not an environment variable. How do I do that? Kindly assist. your help is much appreciated.

Hey @kayal1postman :wave:,

In order for anyone to help here, you would need to share examples of the request body, what actual value you need to get and what part of the response are you verifying it against.

You’re trying to explain it, without actually showing what it is you’re looking at :pray:

Hi,
Below is the request eg:

{
    "DummyObject": {
        "DummyObject1": {
            "Name": "Mr  Doe"
        }
    }
}

Response eg:

{
    "Rip": {},
    "ID": "123VBXXXXXXXXXX",
    "DummyObject": {
        "DummyObject1": {
            "Name": "Mr  Doe"
        }
    }
}

Which field in the request do you want to target?

You can access the body of a request using the following.

const body = JSON.parse(pm.request.body.raw);

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.