#`pm.execution.runRequest` being triggered multiple times

24 messages · Page 1 of 1 (latest)

honest wadi
#
let response = null;

try {
    response = await pm.execution.runRequest("39434079-01e6cd2a-80e3-4699-80c2-1d2510248aa1");
} catch (err) {
    console.error(err);
}

if (response == null) {
    console.error(`response == null`);
}
else if (response.code >= 400) {
    console.error(`Failed to get access token: ${response.json()}`);
} else {
    pm.collectionVariables.set("accessKey", response.json().access);
}

Can you help me understand why does await pm.execution.runRequest triggers infinite times until an error occurs? The console messages are attached. Unfortunately I can't send the full JSON of the logs since they contain sensitive information.

tepid folio
#

What have you done to try and debug this so far? Can you break it up into smaller parts.

Have you tried removing the null variable at the start and that part of the if block?

Is this code part of a wider loop?

What happens if you add the 201 status code to start rather than leave it going for anything not a 400+ code.

It's only going to ever run the method 10 times in the same request and it should stop execution at that point.

honest wadi
# tepid folio What have you done to try and debug this so far? Can you break it up into smalle...

Thank you for your attention @tepid folio!
For the two first points, basically the current state of the code is me trying to debug it. The minimal example was:

response = await pm.execution.runRequest("39434079-01e6cd2a-80e3-4699-80c2-1d2510248aa1");
pm.collectionVariables.set("accessKey", response.json().access);

Which of course had the same problem and I started adding conditionals, logs and error handling to try finding the problem.

For the third point, that is the whole code, there is no loop;

I'm not sure I understood the forth point;

the fifth is the exactly reason I am asking. Why would it trigger the request ten times?

stable oak
#

👀

#

2026-02-23 13:25:20 MST

BLUF: The script is caught in a recursive execution loop. Invoking pm.execution.runRequest() initiates a new Postman request lifecycle, which re-evaluates the Pre-request Script containing this exact code. This self-triggering cycle continues until Postman's failsafe limit (10 iterations) aborts the process.

#

The root vulnerability lies in a lack of execution isolation. In Postman, Collection-level or Folder-level Pre-request Scripts propagate to all child requests.

When Request A triggers the Pre-request Script, it calls Request B (39434079-01...). Because Request B is within the same scope, it also triggers the Pre-request Script before executing. Request B then calls Request C (which is just Request B again), causing infinite recursion. State management here must be conditional; the script must identify its own execution context and halt if it is already processing the target authorization request.

stable oak
#

uhh is it right? lol

honest wadi
#

I mean, it makes sense to me

stable oak
honest wadi
#

I'll try to change to use raw request instead

stable oak
#

That's a Bingo!

honest wadi
#

man, thank you so much

stable oak
#

you're welcome, glad my AI training helped you

#

I just gave it screenshots of the issue

honest wadi
#

damn it

#

"I see LLMs"
"How often do you see them?"
"All the time"

#

good job with your AI anyway

stable oak
#

Thank you. This was an excellent product test.

#

Proved a real world use case of a problem I am solving

#

Infinite Monkey Theory is cool

tepid folio
#

I think there was some missing context in the original message, as to where (which scripting sandbox) this was running from right?

Interested to know what you have changed or where the execution has been moved now.

Is it all working for you now?