Why are specified variables not being remembered?

Good afternoon
I am sending a GET request {{base_url_zakaz}}abonents/v0/abonents?Inn=5534183182&Kpp=553401001

In order to remember the variables, abonentId and requisiteId, received in response to this request. I write down 2 scripts in the Post-Response Script tab:

pm.globals.set('abonent_Id', pm.response.json().abonentId);
pm.globals.set('requisite_Id', pm.response.json().requisiteId);

In response to the request I receive a status of 200 Ok.
And in the body of the response, the necessary variables:

[
    {
        "abonentId": "2202db26-15cb-4abc-a33b-997f966e8043",
        "requisites": {
            "requisiteId": "3a44b0c9-cc36-41d9-9fa2-9578f139e9bd",
            "inn": "5534183182",
            "kpp": {
                "value": "553401001",
                "organizationKppType": 1
            },
            "clientType": 1,
            "name": "LLC Organization Name"
        },
        "accounts": []
    }
]

However, at the same time, in the “Environment Quick Look” tab. For some reason, Postman does not remember the variables received in the body of the response to the request.

In this case, in each of the variables, abonent_Id and requisite_Id, the value is null as the Current Value.

Question: What am I doing wrong and specifying in the request, which is why the specified variables are not being remembered?

Hey @spacecraft-engineer2 :wave:

The is down to the references that you’re making to that response data:

[
    {
        "abonentId": "2202db26-15cb-4abc-a33b-997f966e8043",
        "requisites": {
            "requisiteId": "3a44b0c9-cc36-41d9-9fa2-9578f139e9bd",
            "inn": "5534183182",
            "kpp": {
                "value": "553401001",
                "organizationKppType": 1
            },
            "clientType": 1,
            "name": "LLC Organization Name"
        },
        "accounts": []
    }
]

It’s an array, with an object inside it. Directly going to the abonentId property would result in it being undefined. You need to first specify which object within the array, you want to access.

The Postman Console is your friend here, you can use this to see what would be the result if you were to reference things in certain ways.

This is an example of what you’re doing vs accessing the object first:

console.log(pm.response.json().abonentId)
console.log(pm.response.json()[0].abonentId)


I’ve previously shared this with you in a different thread but this will hopefully explain again how to extract different pieces of data from a response body:

1 Like

Danny Thank you very much!! This is not the first time your method has helped me. It’s good that there are such good specialists like you!! :slight_smile:

P.S. I’m already writing my next request to you…

1 Like

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