Reading an old Postman script, which identifiers mark it as legacy sandbox globals rather than pm API?
answer
- Current API lives on one object
- Bare nouns are the giveaway
- A spelled-out receiver instead of two letters
- Bundled libraries used to be globals
basics
~20 sEverything in Postman's current script API hangs off the single pm object, so bare identifiers such as tests, responseCode, responseBody and the postman command object, plus bundled globals like tv4, xml2Json, CryptoJS and underscore, are the legacy spelling.
solid answer
~40 sThe quickest reading rule: **current sandbox API is reached through `pm`**. Anything that is neither a JavaScript builtin nor a variable the script itself declared, and still resolves, came from the **legacy compatibility layer**. In practice that means the bare `tests` object, the `postman` command object (`postman.setEnvironmentVariable`, `postman.setNextRequest`), the bare reply readers `responseCode` and `responseBody`, and the bundled library globals `tv4`, `xml2Json`, `CryptoJS` and `_`. Each has a current counterpart under `pm` — `pm.test`, `pm.environment.set`, `pm.execution.setNextRequest`, `pm.response.code`, `pm.response.text()` — and the libraries are reached through the sandbox's module surface instead of as globals. None of the old names fail when used; they warn once and then answer, so reading is the only way to spot them.
code
javascript · 2 linesvar oldWay = responseBody;
var newWay = pm.response.text();go deeper
Be ready to point at a script and say which lines are legacy. The rule is short: current API is on pm, and bare names like tests, responseCode and responseBody are not.
Explain why reading is required at all: the compatibility layer answers the old names after one warning, so nothing in the script's behaviour distinguishes the two spellings.
Demonstrate that you would not rely on eyes alone. Use the use sandbox2 pragma to turn recognition into a check, and treat mixed scripts as the normal case rather than the exception.
Own the standard: decide which spelling new scripts are allowed to use and where that is enforced, so recognition is not a skill every reviewer has to re-apply by hand.
## The one-object rule Postman's script sandbox exposes its current API through exactly one object: `pm`. If a script reads the reply, writes a variable, records a named test or steers the sequence, the current spelling for all of that starts with `pm.`. That gives you a reading rule that costs no memorisation at all: > A bare identifier that is not a JavaScript builtin, not declared by the script, and still resolves, came from the **legacy compatibility layer**. The layer exists because Postman scripts written before the `pm` object was introduced are still in circulation, still stored in collection files, and still executed. Rather than break them, the sandbox keeps the old names available: touching one produces a deprecation warning for that name, once, and then returns the real value. Nothing fails, which is precisely why recognising the names by eye is a real skill rather than something the tool tells you. ## The names you will actually meet | legacy identifier | what it was for | current spelling | |---|---|---| | `tests["name"] = value` | recording a pass or fail | `pm.test(name, fn)` | | `responseCode` | reading the reply's status | `pm.response.code` | | `responseBody` | reading the reply's body text | `pm.response.text()` | | `postman.setEnvironmentVariable(k, v)` | writing an environment value | `pm.environment.set(k, v)` | | `postman.setNextRequest(name)` | steering which request runs next | `pm.execution.setNextRequest(name)` | | `tv4`, `xml2Json`, `CryptoJS`, `_` | bundled helper libraries | the sandbox's module surface | Two shapes dominate. The first is a **bare noun** — `tests`, `responseCode`, `responseBody` — which reads like an ordinary variable and is easy to skim past. The second is the **`postman` command object**, whose methods spell out in words what the `pm` equivalents express as short paths. If you see the word `postman` used as a receiver in script code, you are reading legacy code; the current object is the two-letter `pm`. ## What the shim does not tell you It is worth being explicit about the limits of what recognition buys you: - **No error marks the code.** The legacy names resolve and return correct values, so the script's behaviour is not a clue. - **The warning fires once per name.** A script using `responseBody` in ten places emits one line, so console noise is not proportional to how legacy the script is. - **The collection file says nothing.** A script is stored as source text; nothing in the file records which spelling it uses. - **Mixed scripts are normal.** Scripts edited over time commonly contain both spellings side by side, so finding one `pm.` call does not clear the rest of the file. ## A first pass over an inherited script 1. **Search for `pm.`** and mentally mark those lines as current. 2. **Look at what is left.** Function calls on a `postman` receiver, and bare nouns that were never declared, are the candidates. 3. **Check the map above** for the current counterpart before rewriting anything, so the change is a rename rather than a redesign. 4. **Prove the negative when you think you are done** by putting the pragma `"use sandbox2";` at the top of the script: it opts the script out of the legacy layer, so any remaining old identifier is undefined and fails loudly instead of quietly working. The conversation an interviewer is usually testing here is small but real: can you read a script somebody wrote years ago, say which half of it is history, and name what goes in its place? Everything current is on `pm`; everything else on that list is the older bare-global spelling that the sandbox still answers out of politeness.
- If nothing errors, how would you catch a legacy identifier you missed by eye?Add `"use sandbox2";` as the script's first statement. That opts the script out of the legacy compatibility layer, so any old bare name is simply undefined and the script fails on the line that uses it. It converts a reading exercise into a mechanical check.
saying these in an interview costs you the question
- Thinks the old names throw errors when used today
- Confuses the legacy postman object with the current pm object
- Assumes the collection file records which spelling a script uses
- Believes one pm call means the whole script is current