Skip to content

JavaScript code

JavaScript shares its execution environment with TypeScript: the same engine, the same API, the same built-in library. This page concentrates on what is specific to it — the compatibility layers.

// `input` = the value received, `vars` = the run variables
const utilisateurs = input.data.filter((u) => u.actif);
console.log(`${utilisateurs.length} utilisateurs actifs`);
return _.sortBy(utilisateurs, 'nom');

This is what lets the scripts of an imported Postman collection work with no rewriting.

SurfaceNotes
pm.variables, pm.environment, pm.globals, pm.collectionVariablesAll mapped onto the single run-variable space
pm.iterationDataThe iteration data
pm.request, pm.responseThe current request and response
pm.test(name, fn), pm.test.skipThe tests
pm.expectThe assertions (chai)
pm.sendRequestAn extra call
pm.infoThe run metadata
pm.vaultThe vault
pm.visualizer.set(template, data)The visualizer
pm.cookies, pm.cookies.jar()The cookies
pm.setNextRequest, pm.execution.setNextRequest, .skipRequest, .locationFlow control
postman.getResponseHeaderThe legacy API
pm.test('le statut est 200', function () {
pm.expect(pm.response.code).to.eql(200);
});
pm.environment.set('commandeId', pm.response.json().id);

For imported Bruno collections: the bru.* object — including bru.runRequest(name) — as well as the test() function used bare.

These layers exist so that nothing breaks at import time. In the medium term, prefer the native boxes: an Assert is more readable than a pm.test buried in a script, it has its two then / else outputs visible in the graph, and its message appears directly in the CI log.