Pm collection variable error undefined

I am trying to set the vlan response as my collection variable, but i am getting ’ cannot read properties of undefined (reading ‘0’). no matter whether i put the 0 in there or not i get some king of undefined error. i am a newbie at this stuff so any help will be appreciated.

const reponse = pm.response.json();
console.log(reponse.vlan[0]);

pm.collectionVariables.set("customId" , response.vlan[0]);
[
    {
        "submitId": "2a7d5d65-2ddb-49a3-9d6d-761e182d3c841719497117219",
        "transactionId": "20240703204004_646_365",
        "status": "SUCCESS",
        "executeDetail": "axos service provision successful.",
        "executeDate": 1720039204095,
        "name": "a56f6db9-1557-4e3e-80e7-d4bc23532e9f",
        "vlan": 5,
        "serviceType": "DATA_SERVICE",
        "inActive": false,
        "deletePolicyMap": false,
        "deleteService": false,
        "changeGlobalVlan": true,
        "changeGlobalCTag": false,
        "deleteL2match": false,
        "aeontcard": false,
        "poncard": true,
        "in-provisioning": false,
        "device-name": "LAB_XGS_OLT-1",
        "ont-port-id": "x1",
        "admin-state": "enabled",
        "ont-id": "110102",
        "subscriber-id": "110101",
        "admin-status": "active",
        "vlan-mode": "N2ONE",
        "option82Action": "insert",
        "policy-map": "Full_Throttle",
        "service-name": "Data",
        "ipv4-hosts": [],
        "config-file-instance": "none",
        "user": "",
        "password": "",
        "uri": "",
        "call-waiting": true,
        "caller-id": true,
        "three-way-calling": true,
        "t38-fax-relay": false,
        "msg-waiting-indicator": true,
        "gr-303": false,
        "address": "0.0.0.0/0",
        "ping": true,
        "traceroute": true,
        "ip-address-family": "ipv4",
        "pon-cos": "derived",
        "pppoe-ia": {
            "admin-state": "enabled"
        },
        "transport-type": "udpip",
        "voice-port": [
            "x1"
        ],
        "disable-when-on-battery": true,
        "shutdown": "false",
        "is10GECard": false,
        "isAEONTCard": false,
        "isPONCard": true,
        "cardType": "PON",
        "display-status": "Provisioned Success"
    }
]

Your response is an array, so it should be

response[0].vlan
1 Like

Hey @brabon :wave:

Welcome to the Postman Community :postman:

Have you tried:

console.log(response[0].vlan);

Just noticed the potential spelling mistake.

const reponse = pm.response.json();
pm.collectionVariables.set("customId" , response.vlan[0]);

The parsed response variable is called “reponse” not “response”.

The response is still an array, so you will need reponse[0] or response[0] before you can target the vlan element within that object.

Thank you all for your help. Once i properly spelled response the following did the job.

const response = pm.response.json();
console.log(response[0].vlan);

pm.collectionVariables.set(“customId” , response[0].vlan);

However, now I’m trying to set the subscriber-id value from this same response and I’ve tried it by itself, with “” and with [“”] and cannot get it to work. I get unexpected string or unexpected token.

This is what I have.

const response = pm.response.json();
console.log(response[0].subscriber-id);

pm.collectionVariables.set(“customId” , response[0].subscriber-id);

That would be the same as this:

Thank you! That got it!

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