Conditional Workflows in Postman

Ankit Sobti
The RESTful Web
Published in
3 min readMar 22, 2016

--

There are some products available in the market to create and execute API workflows. However, most of them are limited by their linear, non-reactive execution. We knew we could create something much more effective and decided to add workflow support to Postman. Postman 4.0, in conjunction with Newman, the command line companion, is now powerful enough to help you create and execute non-linear workflows in your Collections!

This latest release builds upon our existing Collection Runner. It introduces a new function called postman.setNextRequest. As is evident from the name, you just need to specify the name of the subsequent request and the runner will take care of the rest. It has the following signature:

postman.setNextRequest(“Request Name”);

Let’s go over an example workflow so you can get a sense of how this works.

You might have met Postman’s Chief Happiness Officer earlier.

This is Cooper. He’s one year old and eats three meals a day. He’s allowed to eat only six pre-approved food items. We store them in a database. Cooper is very picky. You can’t repeat an item on the same day unless you want to risk a tantrum. So I want to generate a random meal plan for him at the beginning of the week.

The workflow:

First makes the API call to GET the list of approved food for Cooper from the database.

Then it creates an entry for each day, 3 times a day, 7 days a week

All 3 meals in a single day have to be unique.

If the API call fails, poor Cooper goes hungry 😟

You can check out the documentation for the collection here and download the collection here:

In case you’re curious, I ran the collection and here’s what Cooper’s eating this week!

In general, the postman.setNextRequest parameter is associated with the request and can be set in the pre-request or the test script. In case of more than one assignment, the last set value is considered. If postman.setNextRequest is absent, the runner defaults to the linear execution and moves to the next request. postman.setNextRequest(null) terminates execution.

I hope you find this useful. postman.setNextRequest is just the beginning and we will push out more APIs to easily create complex workflows in the coming quarters within Postman. Stay tuned!

--

--

Ankit Sobti
The RESTful Web

CTO | Postman. Passionate about building products and companies.