Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change URL in Scripts

Tags:

postman

I need to change URL of the API in the Postman script before the request is submitted. I see that URL variable is exposed but it's readonly. Is there anyway to accomplish what I need to do?

like image 919
Dmitriy Avatar asked Jun 27 '26 20:06

Dmitriy


1 Answers

You can use this function within the pre-request script to change the URL before sending the request.

pm.request.url.update({protocol: "https", host: "jsonplaceholder.typicode.com/posts"})

The main request is set to hit the postman-echo service but the script changes this and sends it to the jsonplaceholder site.

Postman

More information about the types of options you can have in the update function, can be found here:

http://www.postmanlabs.com/postman-collection/Url.html

like image 77
Danny Dainton Avatar answered Jun 30 '26 15:06

Danny Dainton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!