0

All examples I've seen of calling a REST API within a Pre-Request script use the http API pm.sendRequest().

I'd much rather 'submit' a request that is defined through the Postman UI. Then, the request details can easily be managed through the Postman UI and shared across multiple Pre-Request scripts.

Is there a Postman API to send/invoke a specific request item in a collection?

MarkE
  • 123
  • 8
  • 1
    The challenge is that sendRequest() is asynchronous and based on a raw HTTP request, not a Postman-defined request. And although setNextRequest() supports a Postman request identifier, it occurs after the execution of the script. I was hoping there is a synchronous way to send a request based on the request identifier within a script. – MarkE May 16 '22 at 18:30

1 Answers1

0

What you're looking for is postman.setNextRequest()

You can check the documentation here: Building request workflows

Christian Baumann
  • 3,188
  • 3
  • 20
  • 37
  • Thanks, but I don't think that setNextRequest() solves my need. The Postman documentation states: "the postman.setNextRequest() function is always executed at the end of the current request." I need to immediately invoke a request by providing the Postman request ID. – MarkE May 16 '22 at 18:26
  • @MarkE, I think the idea is, you run the linked request and at the end of it, use setNextRequest() to call the request you're describing above. – T Nguyen Feb 02 '23 at 07:30
  • @MarkE How did you solve that? – Manoel Vilela May 11 '23 at 12:59
  • I never found a way to automate automatically calling a prerequisite API. So I usually manually all of them in sequence and use variables to map outputs from one call to another. – MarkE May 15 '23 at 20:42