Hello everybody!
In this short topic I want to show you how you can use automatization in Postman App.
In my case I will automate the process of getting Beaber token from Azure AD and use it in my “main” request.
First, we need to add all variables to our request. I simply created New Application in Azure AD -> Enterprise applications.


Second step – let’s add out script to Pre-request Script tab:

const postRequest = {
url: ‘https://login.microsoftonline.com/’ + pm.variables.get(“tenantId”) + ‘/oauth2/token’,
method: ‘POST’,
header: ‘Content-Type: application/x-www-form-urlencoded’,
body: {
mode: ‘urlencoded’,
urlencoded: [
{key: “grant_type”, value: “client_credentials”, disabled: false},
{key: “client_id”, value: pm.variables.get(“clientId”), disabled: false},
{key: “client_secret”, value: pm.variables.get(“clientSecret”), disabled: false},
{key: “resource”, value: pm.variables.get(“resource”), disabled: false},
]
}
};
pm.sendRequest(postRequest, (error, response) => {
const jsonResponse = response.json();
pm.environment.set(“access_token”, jsonResponse.access_token);
console.log(error ? error : response.json());
});
The last step – create GET request to Azure API:
https://management.azure.com/subscriptions/{{subscriptionId}}/resourcegroups?api-version=2017-05-10
As you can see, we got info about Resource Groups in our Subscription (do not forget to add necessary permissions for Application in your Subscription).
Here we see 2 requests: one for get beaber token, second request to Azure:

Thanks!