So I’m pretty new to postman scripting, but I think this might work for you. If I know the index of my parameter to update, as it seems you are wanting to do, I have been successful with
I have created a generic function for adding query params to request query. It will update or insert request query based on the key. It does extra check for the key is it falsey and make value empty string if value is falsey.
function upsertQueryParams(key, value) {
if (!key) {
throw new Error('Empty query param key.');
}
pm.request.url.query.upsert({ key, value: value || '' });
}
I could never get these examples to work for me. So, rightly or wrongly, I finally resorted to removing the queryParam and adding it back in the pre-request script.
FYI, for anyone who is looking at this years later and going insane thinking pm.request.url.query is an Array: it is not: Url - Postman Documentation shows that the url’s member “query” is a PropertyList.<QueryParam>.