skip to content

What does a call sent by pm.sendRequest in a Postman script not get that a stored collection request gets?

level: middleimportance: must knowfreq 62%

answer

  1. Events hang off items, not off requests
  2. A script built it, so no item exists
  3. Nothing listens, so nothing fires
  4. The sequence never notices the call happened
  5. pm.response still means the current item's reply

basics

~20 s

It gets no events and no place in the run. Because a script builds it rather than the collection holding it, no item exists, so no pre-request or test script fires for it and the sequence of requests is unchanged.

solid answer

~40 s

In the Postman sandbox, `pm.sendRequest` hands a script-built request straight to the host runtime's HTTP command, tagged `source: 'script'`. What travels with a stored request is an **item** — the collection entry that owns its `event` list — and a side call has no item at all. So nothing listens for it: no pre-request script, no test script, and none of the ancestor scripts that would cascade from the collection or a folder. It also occupies no step in the sequence, so the run's position is untouched and the reply never lands in `pm.response`; the only place it exists is the callback you passed. Everything you want to happen around a side call, you write yourself, in that callback.

go deeper

for a junior

Recall that a script-fired call is not a request in the collection: no scripts run for it, and the reply comes back only in the callback you passed to the call.

for a middle

Explain the mechanism: events are declared on items, a side call has no item, so nothing fires and nothing cascades. Be able to list what is lost — events, a step in the sequence, a place in the output.

for a senior

Diagnose the real symptom: work that quietly stopped happening after a request was rewritten as script code. Show you know which behaviour belongs to the item and which to the script that fired the call.

for a principal

Own the judgment about which errands are allowed to disappear into script code and which must remain visible requests, and the cost that invisible traffic imposes on whoever reads a failing run.

## The unit that carries events is the item A Postman collection is a tree of **items**. An item is the stored entry that holds a request together with its `event` list — the scripts declared on it — and its position among its siblings. When a run executes, it walks that tree: for each item it fires the pre-request event, sends the request, fires the test event, and moves on. `pm.sendRequest` does not put an item into that walk. The sandbox serialises the request object your script built and raises a bridged HTTP command tagged `source: 'script'`; the host performs the exchange and answers into your callback. **No item is created, so nothing that hangs off an item can happen.** That single sentence is the whole answer, and every consequence below falls out of it. ## What does not happen - **No pre-request script runs** for the side call — not the target endpoint's, because no stored request was consulted to build it. - **No test script runs** for it either; nothing is executed after the reply lands except the callback you wrote. - **No ancestor script cascades.** A collection-level or folder-level script runs because an item underneath it is being executed; there is no item here to sit underneath anything. - **No step is consumed.** The run's position among the collection's requests is exactly what it was before the call. - **The reply is not `pm.response`.** That name refers to the reply of the item currently executing; the side call's answer exists only as the callback's second argument. - **No file data goes out.** The sandbox strips file parts from a script-built body — the wording it uses is that uploading files from scripts is not allowed. ## Side by side | | A request stored as an item | A call made with `pm.sendRequest` | |---|---|---| | Where the request is defined | in the collection document | in script code, at run time | | Pre-request event | fires | none exists | | Test event | fires | none exists | | Ancestor script cascade | collection, then folder, then item | nothing cascades | | Position in the run's sequence | occupies one step | occupies none | | How the reply reaches script code | `pm.response` in the test script | the callback's second argument | ## Why the design is this way The separation is deliberate rather than an oversight. Two reasons are worth being able to state: 1. **Termination.** If a script-fired call itself triggered scripts, and one of those scripts fired another call, a collection could recurse without bound. Keeping the side call event-free makes it a leaf by construction. 2. **Honest accounting.** A run's report is meant to describe the collection that was run. If arbitrary script traffic appeared as run entries, the shape of the report would depend on code rather than on the document, and two runs of the same collection could describe different things. ## How this bites in practice The symptoms all look like something silently not happening: - A team moves a setup call out of the collection and into a script and finds the checks that used to run around it are simply gone — they were declared on the item that no longer exists. - Someone expects the side call to appear in the run output as one more request and cannot find it; only the item that fired it is there. - Someone reads `pm.response` after a side call and gets the current item's reply, then draws a conclusion about the wrong endpoint entirely. - A helper script that works alone stops working when it is expected to feed a later request, because the person assumed the side call's own scripts had stored something for it. ## What to do about it The rule of thumb is simple: **if you want the collection's machinery, use the collection.** A call that deserves scripts around it, a name in the report, and a place in the sequence is a request that belongs in the collection as an item. A side call is right when a script needs a fact from somewhere else before it can carry on, and nobody needs to see that errand as a step of its own. When you do use one, remember that everything around it is now yours to write. There is no framework running on the side call's behalf: whatever should happen when the reply lands has to be code you put inside the callback, and it will run in the context of the item that fired it, not in a context of its own.

  • Does the collection-level pre-request script run for a call fired with pm.sendRequest?
    No. An ancestor script runs because an item beneath it is executing, and cascading is resolved from that item's place in the tree. A side call has no item and no place in the tree, so nothing above it is consulted. The only code that runs is the script that made the call and the callback it passed.
  • A setup call was moved from a collection request into a script and its checks disappeared. Why?
    Those checks lived in the item's test event. Moving the call into script code deleted the item, and the event went with it. The reply now arrives only in the callback, so anything that should be verified must be rewritten there — or the call should go back to being a request the collection owns.

saying these in an interview costs you the question

  • Thinks the target request's scripts run for a side call
  • Expects the collection-level script to cascade onto it
  • Believes the side call becomes the next request in the sequence
  • Reads pm.response expecting the side call's reply
  • Assumes the side call shows up as its own entry in run output