Postman Pre-request Script for Azure REST API

When you are using Postman and you are working with Azure, there is a lack of functionality in built-in Authorization options. You can pick an oAuth 2.0 option, but there is no possibility to put "resource" parameter in token request. AWS users are probably much more happy, because they have a dedicated configuration option. For Azure? Not yet.

But it is not so complicated to do it by yourself. In a request to the ARM API ( you need to have Content-Type header and the Authorization header where Bearer token is placed. Use a variable for the token - let say {{access_token}}.

Next, you need to create a Pre-request Script to handle Access Token aquisition from oAuth endpoint in Azure Active Directory - you will find it in "Endpoints" blade inside "Application registration" blade (AAD).

Here you have a code I'm using for Pre-request Script:

As you can see, I'm not hardcoding client_id (Application ID), client_secret (Application Key) and tenant. I have it written in my Postman Environment. This is the same place, where access_token is written, when acquired from oAuth endpoint.

comments powered by Disqus