Sharing tips and tricks with others in the Postman community

Good night,

Sorry I tried to adjust your script to fit my tests, however, the logo does not capture the data I need and I need to capture each account data:

                "holder": "CORREA CHUQUILIN YONI ORLANDO",
                "accountDescription": "Individual account",
                "account": "210022949474",
                "accountType": "10",
                "accountTypeDescription": "SAVINGS ACCOUNT",
                "currency": "840"

Test:

let jsonData = pm.response.json ()

_.each (jsonData.accounts, (result) => {
    pm.globals.set ("holder", result.accounts.holder)
})

Response:

{
    "guid": "9052e4e2-ddfa-4d90-b73f-00a415b674d4",
    "success": true,
    "error": {
        "code": "0000",
        "description": "TRANSACTION OK"
    },
    "result": {
        "date": "0510",
        "msgType": "0210",
        "authorizationCode": "000001",
        "responseDescription": "TRANSACTION OK",
        "variable": {
            "accounts": [
                {
                    "holder": "CORREA CHUQUILIN",
                    "accountDescription": "Individual account",
                    "account": "210022949474",
                    "accountType": "10",
                    "accountTypeDescription": "SAVINGS ACCOUNT",
                    "currency": "840"
                }
            ]
        },
        "prCode": "990000",
        "time": "215212",
        "referenceCode": "",
        "responseCode": "0000"
    }
}

Try this:

let jsonData = pm.response.json().result.variable

_.each(jsonData.accounts, (account) => {
    pm.globals.set("holder", account.holder)
})

You were jumping straight down to the array and missing out some of the nested properties that the array was within.

2 Likes

Good day,

Thank you very much, haha yesterday I had testing and tiredness no longer gave me the logic and I had to go to you.

Thank you very much again

1 Like