Is it possible to set a URL with optional parameters?

Hi,

I’m working on creating a collection which, hopefully will require the least amount of user input possible - ideally users should just input their variables and run the requests.

For a GET request, a base URL will be used, but users may include up to three optional filters to reduce the number of results returned. These filters are appended to the base URL - example https://baseURL.com?filter1&filter2

Is there a way to set up a pre-test script to have the filters added to the base URL if the user chooses to activate the filters via the collection variables?

1 Like

When you mean filters, do you mean query parameters?

Something like…

let collectionVariableCheck = pm.collectionVariables.has('variableName');

console.log(collectionVariableCheck); // true or false

if (collectionVariableCheck === false) {
    pm.request.url.addQueryParams(pm.request.url.query.add({ key: 'newKey', value: 'newValue' }))
}

That worked. Thanks! :smiley:

1 Like