fix: IRIS API - post request script

This commit is contained in:
2026-03-11 17:25:05 +01:00
parent 445a7d62cc
commit b51d6c2383
@@ -7,6 +7,15 @@ http:
method: GET method: GET
url: "{{IrisApiUrl}}/contracts;full?year=2025&wfState=signed&page=1" url: "{{IrisApiUrl}}/contracts;full?year=2025&wfState=signed&page=1"
params: params:
- name: year
value: "2025"
type: query
- name: wfState
value: signed
type: query
- name: page
value: "1"
type: query
- name: pid - name: pid
value: BELL_B_25_CCS_IST_RA_01 value: BELL_B_25_CCS_IST_RA_01
type: query type: query
@@ -39,15 +48,6 @@ http:
value: AMER_F_25_CCS_IST_RA_CODICI_01 value: AMER_F_25_CCS_IST_RA_CODICI_01
type: query type: query
disabled: true disabled: true
- name: year
value: "2025"
type: query
- name: wfState
value: signed
type: query
- name: page
value: "1"
type: query
auth: inherit auth: inherit
runtime: runtime:
@@ -74,7 +74,7 @@ runtime:
// ---------------- URL and Query helpers (SDK-safe) ----------------- // ---------------- URL and Query helpers (SDK-safe) -----------------
// Returns a plain object of query params. Works with: // Returns a plain object of query params. Works with:
// // - pm.request.url.query (SDK v8+ as QueryList) using .toObject() // - pm.request.url.query (SDK v8+ as QueryList) using .toObject()
// - URL that has no query or is a raw string // - URL that has no query or is a raw string
function getQueryObject(url) { function getQueryObject(url) {
try { try {
@@ -202,16 +202,23 @@ runtime:
// Build a function that fetches page N and aggregates // Build a function that fetches page N and aggregates
function fetchPage(n) { function fetchPage(n) {
return new Promise((resolve) => { return new Promise((resolve) => {
//console.log("Setting current page to: " + n);
const nextUrl = setQueryObject(req.getUrl(), { [PAGE_PARAM]: String(n) }); const nextUrl = setQueryObject(req.getUrl(), { [PAGE_PARAM]: String(n) });
setTimeout(function () { const reqHeaders = req.getHeaders
await bru.sendRequest({ url: nextUrl, method: 'GET' }, async function(err, res) {
console.log("Setting headers: " + JSON.stringify(reqHeaders));
setTimeout(async function () {
console.log("Calling next URL... (" + nextUrl + ")");
await bru.sendRequest({ url: nextUrl, method: 'GET', headers: reqHeaders }, async function(err, res) {
if (err || !res) { if (err || !res) {
console.log("Error fetching page " + n + " (err: " + JSON.stringify(err) + ")");
test('Error fetching page ' + n, function () { test('Error fetching page ' + n, function () {
expect(err).to.eql(null); expect(err).to.eql(null);
}); });
return resolve(false); return resolve(false);
} }
const ok = res.status >= 200 && res.status < 300; const ok = res.status >= 200 && res.status < 300;
console.log("Next URL response: " + ok);
if (!ok) { if (!ok) {
test('Non-2xx on page ' + n + ' - stop further paging', function () { test('Non-2xx on page ' + n + ' - stop further paging', function () {
expect(ok).to.eql(true); expect(ok).to.eql(true);
@@ -222,13 +229,16 @@ runtime:
const json = safeJson(body); const json = safeJson(body);
const items = json ? getItemsFromResponseBody(json) : []; const items = json ? getItemsFromResponseBody(json) : [];
considerItems(items); considerItems(items);
resolve(true); return resolve(true);
}); });
}, RATE_LIMIT_DELAY_MS); }, RATE_LIMIT_DELAY_MS);
}); });
} }
async function run() { async function run() {
console.log("Running...");
console.log("Total pages found: " + totalPages);
// If there are more pages, iterate // If there are more pages, iterate
for (let p = currentPage + 1; p <= totalPages; p++) { for (let p = currentPage + 1; p <= totalPages; p++) {
const cont = await fetchPage(p); const cont = await fetchPage(p);
@@ -243,7 +253,7 @@ runtime:
})); }));
// Save to environment // Save to environment
bru.setEnvVar(TARGET_ENV_VAR, JSON.stringify(output)); bru.setVar(TARGET_ENV_VAR, JSON.stringify(output));
// Basic summary tests // Basic summary tests
test('Aggregated items have required properties', function () { test('Aggregated items have required properties', function () {