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);

1 Answer 1

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

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!
    – Kreidol
    Commented Jan 11, 2022 at 0:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.