diff --git a/collections/IRIS GW (Gateway) REST API (v1)/Contracts/Get Contracts with two or more participants (scripted).yml b/collections/IRIS GW (Gateway) REST API (v1)/Contracts/Get Contracts with two or more participants (scripted).yml index 36d48ec..c0a4432 100644 --- a/collections/IRIS GW (Gateway) REST API (v1)/Contracts/Get Contracts with two or more participants (scripted).yml +++ b/collections/IRIS GW (Gateway) REST API (v1)/Contracts/Get Contracts with two or more participants (scripted).yml @@ -7,6 +7,15 @@ http: method: GET url: "{{IrisApiUrl}}/contracts;full?year=2025&wfState=signed&page=1" params: + - name: year + value: "2025" + type: query + - name: wfState + value: signed + type: query + - name: page + value: "1" + type: query - name: pid value: BELL_B_25_CCS_IST_RA_01 type: query @@ -39,15 +48,6 @@ http: value: AMER_F_25_CCS_IST_RA_CODICI_01 type: query disabled: true - - name: year - value: "2025" - type: query - - name: wfState - value: signed - type: query - - name: page - value: "1" - type: query auth: inherit runtime: @@ -74,7 +74,7 @@ runtime: // ---------------- URL and Query helpers (SDK-safe) ----------------- // 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 function getQueryObject(url) { try { @@ -198,20 +198,27 @@ runtime: // Figure out current page from request URL (query param 'page') const currentQuery = getQueryObject(req.getUrl()); const currentPage = parseInt(currentQuery[PAGE_PARAM] || '1', 10) || 1; - + // Build a function that fetches page N and aggregates function fetchPage(n) { return new Promise((resolve) => { + //console.log("Setting current page to: " + n); const nextUrl = setQueryObject(req.getUrl(), { [PAGE_PARAM]: String(n) }); - setTimeout(function () { - await bru.sendRequest({ url: nextUrl, method: 'GET' }, async function(err, res) { + const reqHeaders = req.getHeaders + + 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) { + console.log("Error fetching page " + n + " (err: " + JSON.stringify(err) + ")"); test('Error fetching page ' + n, function () { expect(err).to.eql(null); }); return resolve(false); } const ok = res.status >= 200 && res.status < 300; + console.log("Next URL response: " + ok); if (!ok) { test('Non-2xx on page ' + n + ' - stop further paging', function () { expect(ok).to.eql(true); @@ -222,13 +229,16 @@ runtime: const json = safeJson(body); const items = json ? getItemsFromResponseBody(json) : []; considerItems(items); - resolve(true); + return resolve(true); }); + }, RATE_LIMIT_DELAY_MS); }); } async function run() { + console.log("Running..."); + console.log("Total pages found: " + totalPages); // If there are more pages, iterate for (let p = currentPage + 1; p <= totalPages; p++) { const cont = await fetchPage(p); @@ -243,7 +253,7 @@ runtime: })); // Save to environment - bru.setEnvVar(TARGET_ENV_VAR, JSON.stringify(output)); + bru.setVar(TARGET_ENV_VAR, JSON.stringify(output)); // Basic summary tests test('Aggregated items have required properties', function () {