
It’s great that we now have a tool that is malleable enough for developers to get their work done, while also providing an easy interface for non technical teammates to explore your system’s endpoints. Luckily, Postman has provided all of the tools to test workflows in non production environments and review logs. It also introduces the ability to test complex workflows that depend on the results of multiple endpoints. The dynamic nature of scripting each endpoint in a collection opens up a ton of doors for helping you develop your endpoints fast. Once again, Postman proves that it does more than you ever thought you needed.
POSTMAN SCRIPT AUTOMATION HOW TO
I suggest reading the Postman docs for a full overview of the different levels of variables, how to work with them.īefore getting started, with this automation approach, sync with your team on how you all can work best within Postman’s ecosystem. This is tricky because now when you run the “Get Company” endpoint, you’ll be overwriting the environment for everyone. Back to our example, if we have a default `` in our environment configuration so that we can quickly run endpoints without having to hit the “Get Company” endpoint first, we’ll need to overwrite the environment with tEnvironmentVariable(.). The response viewer at the bottom contains a corresponding Test Results. In the Postman app, the request builder at the top contains the Tests tab where you write your tests. Tests can be run as part of a single request or run with a collection of requests. Postman has a tiered system for it’s variables, with Environment Variables taking precedence. Tests are scripts written in JavaScript that are executed after a response is received. In this example, I covered how to set Global Variables. Parse the response into JSON that we can use:

POSTMAN SCRIPT AUTOMATION CODE
In the Pre-request Script tab, I can enter the following code to set the company-id:
POSTMAN SCRIPT AUTOMATION UPDATE
Now let’s say I need to use the company ID on a subsequent update request: PUT /api/v1/company/. Postman provides a really easy interface for setting these variables through the “Pre-request Script” tab on your endpoints.įor example, let’s say that I have this endpoint that gets details about a specific company: GET /api/v1/company/. You’ll use Pre scripts to dynamically set variables that you’re sending, while Test scripts will set response variables. Scripting is split into two patterns: Pre-request scripts and Test scripts. Once you understand the Postman ecosystem, you’ll be able to dynamically set the variables you send to endpoints, as well as the responses you get.Īnd the best part is that you can use JavaScript to write these scripts Prerequest scripts Postman allows you to automate setting variables by adding scripts to your collections. Not any more! Speeding up workflows through automation

Being able to easily define things like which environment you’re testing against is great.īut what about when you want to automate setting these variables? For example, if you have a workflow that depends on the response of an initial request, you’ll have to manually set that value each time you run through the workflow, right? Variables are one of the best features of Postman.
