Replace pm.sendRequest when you move scripts to Requestarium
pm.sendRequest lets a Postman script send a second request in the middle of the first one. It's popular for fetching tokens, looking things up and cleaning up. Requestarium doesn't support it yet: the import preview lists every script that calls it, and those calls fail when the script runs.
The good news: almost every pm.sendRequest falls into one of four patterns, and each has a replacement that's easier to read and debug, because the hidden request becomes a real one you can see in the run.
Find the scripts that need work
Import the collection and open the Scripts section of the preview. Each script is listed with what was converted, what runs through a compatibility layer and what won't work. Download the report as Markdown to work through it. From the CLI:
requestarium import orders.postman_collection.json --preview --script-report scripts.mdPattern 1: fetching a token
The Postman version, often on the collection:
pm.sendRequest({
url: pm.environment.get('authUrl'),
method: 'POST',
header: { 'Content-Type': 'application/json' },
body: { mode: 'raw', raw: JSON.stringify({ clientId: '…', clientSecret: '…' }) },
}, (err, res) => pm.environment.set('token', res.json().access_token));If it's OAuth 2.0 (client credentials, authorization code with PKCE, password), delete the script and set the collection's Authorization to OAuth 2.0. Requestarium gets the token and refreshes it, and requests inherit it. See OAuth 2.0 in your API client.
If it's a custom login, make it a request:
- Add Get token as the first request in the folder:
POST {{authUrl}}with the body. - Its post-response script saves the token:
pm.test('got a token', () => pm.expect(pm.response.json().access_token).to.be.a('string'));
pm.environment.set('token', pm.response.json().access_token);- Set the folder's auth to Bearer token with
{{token}}.
The runner sends Get token first, and every request after it uses the token. See chain API requests and pass a token.
Pattern 2: a lookup before the request
// Postman: find the product id by SKU, then use it
pm.sendRequest(`${pm.environment.get('baseUrl')}/products?sku=ABC-1`, (err, res) => {
pm.environment.set('productId', res.json().data[0].id);
});Replace it with a request named Find product by SKU, placed before the one that needs it:
// Find product by SKU — post-response
const product = pm.response.json().data[0];
pm.test('product exists', () => pm.expect(product).to.exist);
pm.environment.set('productId', product.id);Now the lookup has its own test. When the product is missing, the report says so, instead of the next request failing with a confusing 404.
Pattern 3: clean-up after the test
// Postman: delete what the test created
pm.sendRequest({ url: `${base}/orders/${id}`, method: 'DELETE' });Make it a Delete order request at the end of the folder. In a test suite, set its role to Clean up: clean-up steps run last and always run, even when a test failed, so data doesn't pile up. See setup and clean-up steps.
Pattern 4: polling or retrying
// Postman: ask again until the job is done
function poll() {
pm.sendRequest(`${base}/jobs/${id}`, (err, res) => {
if (res.json().status === 'running') setTimeout(poll, 1000);
});
}Make Check job a request that sends itself again while the job runs:
const status = pm.response.json().status;
if (status === 'running') pm.execution.setNextRequest('Check job');Run with a delay between requests (--delay 1000) and cap the number of attempts. Details in control the order of a collection run.
For retries on 502, 503 and 504, you don't need a script at all: --retries 3 in the CLI resends with a backoff.
What about one-off calls in a single Send?
If a script needs another request on a single Send, there's no direct replacement yet: a single Send sends one request. Run the folder instead (Run folder, or requestarium run-collection --folder), or send the helper request by hand first.