Postman Get value of url request parameter to do a test
Asked Answered
J

1

6

I am trying to get a url from the get request params.

How to Construct request URL from environment variables

In Pre-request script urlwfsservice and orderid is set from environment variables

{{urlwfsservice}}/v1/merchantorders/{{orderId}}/BoardingActivities.updateMerchantToHub.REQUEST/details/

When use

var urlnew =request.url;
console.log(request.url);

I get this output as variables name not actual value or url

{{urlwfsservice}}/v1/merchantorders/{{orderId}}/BoardingActivities.updateMerchantToHub.REQUEST/details/

how can I get output like below simpleurl ?

var simpleurl = “https://dev-someweburl.com/v1/merchantorders/ZN2aB/BoardingActivities.updateMerchantToHub.REQUEST/details/”;

Complete Pre-request script Code

// how to Construct request URL from environment variables
console.log("logging url");
var urlnew =request.url;
console.log(urlnew);
//var url = "https://dev-someweburl.com/v1/merchantorders/ZN2aB/BoardingActivities.updateMerchantToHub.REQUEST/details/";
var retryDelay = 200;
var retryLimit = 5;

function isProcessingComplete(retryCount) {
    pm.sendRequest(urlnew, function (err, response) {
        if(err) {
            // hmmm. Should I keep trying or fail this run? Just log it for now.
            console.log(err);
        } else {
            // I could also check for response.json().results.length > 0, but that
            // would omit SUCCESS with empty results which may be valid
            if(response.json().auditRecords.length === 0) {
                if (retryCount < retryLimit) {
                    console.log('Job is still PENDING. Retrying in ' + retryDelay + 'ms');
                    setTimeout(function() {
                        isProcessingComplete(++retryCount);
                    }, retryDelay);
                } else {
                    console.log('Retry limit reached, giving up.');
                    postman.setNextRequest(null);
                }
            }
        }
    });
}

isProcessingComplete(1);
Jacklynjackman answered 22/6, 2021 at 21:3 Comment(0)
B
16
console.log(pm.variables.replaceIn(pm.request.url.toString()))

you can use replaceIn method to replace variables to its actual values. Also use pm. as pm is the new api or syntax in postman

Backandforth answered 23/6, 2021 at 6:30 Comment(1)
"The toString() method returns a string representing the object." Would have never guessed I needed toString() to add a query param conditionally based on whether the path included a specific word. Thanks, this answered my question, too!Unsustainable

© 2022 - 2024 — McMap. All rights reserved.