I have a scenario where I have to change the request method from POST to a GET, based on a given condition. How do I do that?
Scenario:
-
Request method originally is a POST
-
Read the condition1 from environment
-
If condition1 === true then pm.request.method.update(“GET”)
something like this.
-
I only want to change the method, nothing else.
-
similar to how you add header dynamically using pm.request.methods.add method.
-
I don’t want to use a getRequest method I only want to update the method from POST to GET.
Thanks in Advance.
Hi @MrAutomationGuy, did you know about the fact that Postman let’s you define custom methods also?
And you can use that to your advantage by making the request method itself a variable.
You can type in the method as {{METHOD}}
or anything else as you’d like.
Then in your pre-request script, you can check your conditions as you’d like and make use of local
variable or any other variable scope as you wish to and change the request method accordingly.
Something like so:
2 Likes
omg, thank you @singhsivcan. Yes yes, that resolved my issue. Where is this documented? that’s why you are a leader
Thank you Sir.
Thanks to you I found the link too: Custom HTTP Methods == More Flexibility and Autonomy | Postman Blog
2 Likes