15 Day Challenge Day 6

How to store a collection variable from response body like session token which is dynamic and use it in another request ?
i want to store the session Id data and user id data and use it in

Hi @security-technologi7

I think you are missing a property “response”.



Once you save it as a collection variable like in your example you would need to use the pm.collectionVariables.get("variable_key"); option to grab it in the pre-req script of your other calls.

thank you @w4dd325 Postman API Tester
I have another doubt
When I try to get the collection variable from pre-req scrip I am getting 403 error
Could you tell what i am missing

could you provide more info?

maybe screenshots of what you are trying?

Thanks for your response @w4dd325
I figured it out myself
The problem is I didn’t pass the token value So I got 403 error
Thanks for your time

Hello, everyone. I am facing the error “TypeError: Cannot read properties of undefined (reading ‘find’)”. Does anyone please help me with this?

hi @chi.pham ensure each request has at least one test


This one is not quite so easy to troubleshoot as that “test” has a fair bit of code. It doesn’t just contain a single find request which would make it easy to work out which bit is failing.

pm.test("Tests added correctly", () => {
    let newFlowFolder = scenarioFolder.item.find(fol => { return fol.name === "New user workflow" })

    let firstRequest = newFlowFolder.item.find(req => { return req.name === "User Login" | req.name === "User Login Copy"})
    let firstTest = firstRequest.event.find(event => {return event.listen === "test"})
    pm.expect(firstTest.script.exec.toString(), 'check first test').to.include("pm.test")

    let secondRequest = newFlowFolder.item.find(req => { return req.name === "Account summary" | req.name === "Account summary Copy"})
    let secondTest = secondRequest.event.find(event => {return event.listen === "test"})
    pm.expect(secondTest.script.exec.toString(), 'check second test').to.include("pm.test")

    let thirdRequest = newFlowFolder.item.find(req => { return req.name === "User Logout" | req.name === "User Logout Copy"})
    let thirdTest = thirdRequest.event.find(event => {return event.listen === "test"})
    pm.expect(thirdTest.script.exec.toString(), 'check third test').to.include("pm.test")

    let fourthRequest = newFlowFolder.item.find(req => { return req.name === "Account summary 2"})
    let fourthTest = fourthRequest.event.find(event => {return event.listen === "test"})
    pm.expect(fourthTest.script.exec.toString(), 'check fourth test').to.include("pm.test")
    pm.expect(fourthTest.script.exec.toString(), 'check 403').to.include("403")

    pass += 1

When you get “Cannot read properties of undefined (reading 'find)”. It means the object that its trying to perform the find against is undefined.

Let’s take the first line as an example.

let newFlowFolder = scenarioFolder.item.find(fol => { return fol.name === "New user workflow" })

If the error was being caused by this line, it would actually mean that “scenarioFolder.item” can’t be found. This object should be an array (as the find function works against arrays).

scenarioFolder is set earlier (and I don’t think its this one that its failing on).

let scenarioFolder = collection.item.find(fol => {return fol.name === "API tests"})

Usually, this is just a problem with the naming of a folder or request. So please check the spelling. You can see within the tests what the folder or request names should be. Although on face value, I can’t see what is wrong with your folder structure. I would perhaps clone the submit collection request and add a few console logs within the tests to double check that the variables are returning correctly. newFlowFolder, firstRequest, firstTest, etc.